public string AddStudent([FromBody] studentInfo student) { try { _db.studentInfo.Add(student); _db.SaveChanges(); return("Record Added Successfully"); } catch (Exception e) { if (e.HResult == -2146233087) { return("Id Number Already Exists"); } else if (e.HResult == -2146232032) { return("String Too Long"); } return(e.InnerException.InnerException.Message); } }
static void Main(string[] args) { using (SandeepDBEntities db = new SandeepDBEntities()) { Courses cou = new Courses(); cou.CourseId = 5200; Employee emp = new Employee(); emp.EmployeeId = 545; emp.Name = "sandeep"; db.Courses.Add(cou); cou.Employee.Add(emp); db.SaveChanges(); } }
public ActionResult GoogleLoginCallback() { var claimsPrincipal = HttpContext.User.Identity as ClaimsIdentity; var loginInfo = GoogleLoginViewModel.GetLoginInfo(claimsPrincipal); if (loginInfo == null) { return(View("SignIn")); } SandeepDBEntities db = new SandeepDBEntities(); var user = db.UserAccount.FirstOrDefault(x => x.Email == loginInfo.emailaddress); if (user == null) { user = new UserAccount { Email = loginInfo.emailaddress, GivenName = loginInfo.givenname, Identifier = loginInfo.nameidentifier, Name = loginInfo.name, SurName = loginInfo.surname, IsActive = true }; var roleInsert = new Models.Roles { Id = user.Id, RoleName = "user" }; db.UserAccount.Add(user); db.Roles.Add(roleInsert); db.SaveChanges(); } Response.Cookies["Cookie"]["RoleName"] = db.Roles.FirstOrDefault(x => x.Id == user.Id).RoleName; string str = Response.Cookies["Cookie"]["RoleName"]; return(Redirect("signin")); }