Saturday, 30 April 2022

asp.net web api

 https://docs.microsoft.com/en-us/aspnet/web-api/overview/advanced/calling-a-web-api-from-a-net-client

web api send mail code

    public static void SendEmail(string emailbody)

        {

            // Specify the from and to email address

            MailMessage mailMessage = new MailMessage("priyanshpraveen222@gmail.com", "prvn018@gmail.com");

            // Specify the email body

            mailMessage.Body = emailbody;

            // Specify the email Subject

            mailMessage.Subject = "Exception";


            // Specify the SMTP server name and post number

            SmtpClient smtpClient = new SmtpClient("smtp.gmail.com", 587);

            // Specify your gmail address and password

            smtpClient.Credentials = new System.Net.NetworkCredential()

            {

                UserName = "priyanshpraveen222@gmail.com",

                Password = ""

            };

            // Gmail works on SSL, so set this property to true

            smtpClient.EnableSsl = true;

            // Finall send the email message using Send() method

            smtpClient.Send(mailMessage);

        }

sql migration

 https://www.youtube.com/watch?v=Dh0DlCJQ-SQ

copy  database sql from one server to another server


alter column command

ALTER TABLE userregister

ALTER column ID bigint;

change datatype use this
if not work then goto table folders delete constrains which is nothing but primary key

Wednesday, 27 April 2022

publish issues

 sql server publihs issue

version of sql server not taking so use

https://www.mssqltips.com/sqlservertip/2810/how-to-migrate-a-sql-server-database-to-a-lower-version/

publish files asp.net web api 4.1

1.system ->make code remote =off

2.codeman hide tags.

Saturday, 23 April 2022

copy array in console as json Angular

 https://stackoverflow.com/questions/10305365/javascript-chrome-how-to-copy-an-object-from-the-webkit-inspector-as-code

  1. Right-click an object in Chrome's console and select Store as Global Variable from the context menu. It will return something like temp1 as the variable name.

  2. Chrome also has a copy() method, so copy(temp1) in the console should copy that object to your clipboard.

    3.Note on Recursive Objects: If you're trying to copy a recursive object, you will get [object Object]. The way out is to try copy(JSON.stringify(temp1)) , the object will be fully copied to your clipboard as a valid JSON, so you'd be able to format it as you wish, using one of many resources.

    If you get the Uncaught TypeError: Converting circular structure to JSON message, you can use JSON.stringify's second argument (which is a filter function) to filter out the offending circular







parameters default null value

 issue in .net core passing parameter null to parmaeter for sp not working so

i used this tech

https://stackoverflow.com/questions/4153009/operator-cannot-be-applied-to-operands-of-type-string-and-system-dbnull

(object)table.Value ?? DBNull.Value;
 new SqlParameter{ParameterName = "@ProfilePhoto",
                Direction = System.Data.ParameterDirection.Input,
                Value =(object) member.ProfilePhoto ?? DBNull.Value},
https://documentation.help/MS-Enterprise-Library-5.0/EntLib50_d40074bc-fc16-4a1c-8856-60c515e11f3e.html

https://www.learnentityframeworkcore.com/raw-sql

https://visualstudiomagazine.com/articles/2019/07/01/updating-linq.aspx

https://docs.microsoft.com/en-us/aspnet/web-api/overview/data/using-web-api-with-entity-framework/part-3

Thursday, 21 April 2022

db context filter return list

 https://stackoverflow.com/questions/29261734/add-filter-to-all-query-entity-framework

https://entityframework-extensions.net/where-bulk-contains

https://docs.microsoft.com/en-us/ef/core/querying/filters

entity single file upload

 public void ChangePassword(int userId, string password)

{
    var user = new User() { Id = userId, Password = password };
    using (var db = new MyEfContextName())
    {
        db.Users.Attach(user);
        db.Entry(user).Property(x => x.Password).IsModified = true;
        db.SaveChanges();
    }
}

Tuesday, 19 April 2022

fileupload web api


 https://code-maze.com/upload-files-dot-net-core-angular/

important upload files web api and angular using formdata


https://flaviocopes.com/how-to-replace-whitespace-javascript/#:~:text=The%20%5Cs%20meta%20character%20in,occurrence%20of%20the%20white%20space.

https://bobbyhadz.com/blog/javascript-replace-spaces-with-underscores#:~:text=Use%20the%20String.,whitespace%20characters%20replaced%20by%20underscores.


Monday, 18 April 2022

sql issues

 you can change the property.

Tools --> Options --> Designers --> Table and Database designers --> Uncheck --> Prevent saving changes that required table re-creation.

Now you can easily change the column name without recreating the table or losing u r records.



change column type save table changes follow above


https://stackoverflow.com/questions/5136013/how-to-change-column-datatype-in-sql-server-database-without-losing-data


cursor box in visual studo has headache to resolve that we need to

check OVR in below right side bottom in the vsstudio 


to remove this click window + Insert button


git pull not working


use this cmd it will work fine

 git pull origin other-branch

Saturday, 16 April 2022

important

 i have create table in one pc same code pushed to other then credentails is different

so using model .dbmx



update here using the mode.edmx right click then you have generate database from model
in your database table will create automatically.

it is usefull alot


importent

https://social.msdn.microsoft.com/Forums/en-US/home?forum=aspadoentitylinq


enittity blog


https://blog.angular-university.io/angular-file-upload/



Friday, 15 April 2022

list of c# issues

 list of c# issues

call multiples table at a time and save also

and one model have another model list .

mapping mulitple models in the list


https://www.aspsnippets.com/questions/181267/Copy-items-from-one-List-to-another-List-without-foreach-using-Entity-Framework-in-Linq-Query-using-C-in-ASPNet/


https://stackoverflow.com/questions/12715620/how-do-i-return-multiple-result-sets-with-sqlcommand


https://www.sqlservertutorial.net/sql-server-indexes/sql-server-clustered-indexes/


https://www.includehelp.com/dot-net/list-t-addrange-method-with-example-in-c-sharp.aspx

Easy to map different set of list by linq without for loop

https://www.learndapper.com/relationships


core issues 

when using .tolist not able to access the key value

bcz of using .tolist(). so then i used firstordefault()


 var resendotp = _context.Members.Where(x => x.IsActive == true && x.UserId== userMerber.UserId).FirstOrDefault();

                if (DateTime.Now > resendotp.OtpsentDate.Value.AddMinutes(5))


here if we use tolist result will be differenct so used firstordefault





Wednesday, 13 April 2022

forgot sql paasword

 https://www.sqlshack.com/recover-lost-sa-password/

sql pa

ALTER LOGIN sa enable

GO

CREATE LOGIN NewSA WITH PASSWORD = 'Password@1234';


it work but with different username NewSA



Tuesday, 12 April 2022

core issues

   var result=  GetEmployee(id);


   var result= await    GetEmployee(id); 


without await called the method getting error like this.

after giving await issue resolved

https://docs.microsoft.com/en-us/aspnet/core/security/authentication/samples?view=aspnetcore-6.0
https://code-maze.com/password-reset-aspnet-core-identity/

https://stackoverflow.com/questions/67087107/rest-api-hide-password-field-on-response

https://docs.microsoft.com/en-us/ef/ef6/modeling/designer/keyboard-shortcuts




snippets

 C:\Users\Pspl\OneDrive\Documents\Visual Studio 2019\Code Snippets\Visual C#\My Code Snippets

dotnet snippet


Monday, 11 April 2022

react tutorial

 https://www.youtube.com/watch?v=zArp70HTO84&list=PLXIf5ibIbJuwkwflqmcHpQOP5IpSjtsns&index=3


2

https://www.youtube.com/watch?v=zT-rtR9Cl4Q

Saturday, 9 April 2022

asp.net core

 You don't have HttpPostedFileBase in ASP.NET Core 2.0, but you can use IFormFile.

https://www.pdsa.com/downloads


Thursday, 7 April 2022

asp.net 5 apis

 in this return type should be json i did few changes in web.app.config.cs

public class CustomJsonFormatter : JsonMediaTypeFormatter

    {

        public CustomJsonFormatter()

        {

            this.SupportedMediaTypes.Add(new MediaTypeHeaderValue("text/html"));

        }


in register give this line 

 config.Formatters.Add(new CustomJsonFormatter());

issue return type createdaction not working .


issue not working while crateing controller model error while code generator 



https://stackoverflow.com/questions/34992599/cant-add-view-from-controller-in-vs-2015-there-was-an-error-running-the-sele


Wednesday, 6 April 2022

ASP.net core db first appraoch scafolding

2022 latest updated solution is this link  tool link
Scaffold-DbContext "Server=PSPL-HYD-LAP07\PSPLHYD;Database=SMITANGA;User ID=sa;Password=123456789;Trusted_Connection=false;" Microsoft.EntityFrameworkCore.SqlServer -OutputDir Models.


server link

Scaffold-DbContext -Connection  "Server=SQL8002.site4now.net;Database=db_a88748_tmsnew;User ID=db_a88748_tmsnew_admin;Password=09r11a0222;TrustServerCertificate=true;"-Provider Microsoft.EntityFrameworkCore.SqlServer -OutputDir Models -context db_a8638c_tmsContext -force


update model use(Becarefull old model will lose)

Scaffold-DbContext -Connection  "Server=PSPL-HYD-LAP07\PSPLHYD;Database=SMITANGA;User ID=sa;Password=123456789;Trusted_Connection=false;"-Provider Microsoft.EntityFrameworkCore.SqlServer -OutputDir Models -context SMITANGAContext -force


to update model context again

Scaffold-DbContext -Connection "Server=(local);Database=DefenderRRCart;Integrated Security=True;Trusted_Connection=True;" -Provider Microsoft.EntityFrameworkCore.SqlServer -OutputDir RRStoreContext.Models -context RRStoreContext -Project RR.DataAccess -force

 Scaffold-DbContext -Connection "Server=SQL8003.site4now.net;Database=db_a8638c_tms;User ID=db_a8638c_tms_admin;Password=09r11a0222;Integrated Security=True;Trusted_Connection=false;" -Provider Microsoft.EntityFrameworkCore.SqlServer -OutputDir Models -context SMITANGAContext -force 

use this

install this first

1.  Microsoft.EntityFrameworkCore.SqlServer 

2.Microsoft.EntityFrameworkCore.Tools


for .net6 Updated connection string:

 Scaffold-DbContext "Server=PSPL-HYD-LAP07\PSPLHYD;Database=MYFASHO;User ID=sa;Password=123456789;Encrypt=False;TrustServerCertificate=False;Connection Timeout=30;" Microsoft.EntityFrameworkCore.SqlServer -OutputDir Models

  services.AddDbContext<DB_9F30C5_FMSContext>(options =>

                  options.UseSqlServer(Configuration.GetConnectionString("FMSWebApiTestContext")));

            services.AddCors(options =>

            {

                options.AddDefaultPolicy(

                    builder => builder.AllowAnyOrigin()

                    .AllowAnyMethod()

                    .AllowAnyHeader()

                    //.AllowCredentials()

                    );

            });


https://stackoverflow.com/questions/41233300/update-entity-class-in-asp-net-core-entity-framework



trusted connection true to false if get error security 

Car pooling app

 I'll create a car pooling app with real-time vehicle tracking, pickup/drop time estimates, and a list of onboard users. Since we don...