public ActionResult Register(Register model) { if (!ModelState.IsValid) { return(View(model)); } using (var context = new GvGenEntities()) { var mailExists = context.TUsers.FirstOrDefault(m => m.Email == model.Email); if (mailExists == null) { var entity = new TUser(); entity.Name = model.Email; entity.Email = model.Email; entity.Password = model.Password; entity.Role = (int)AuthRole.User; context.TUsers.Add(entity); context.SaveChanges(); return(RedirectToAction("ConfirmEmail")); } else { ModelState.AddModelError("Email", "Your email has been existed in the system."); return(View(model)); } } }
public ActionResult ChangePassword(ChangePasswordViewModel model) { if (!ModelState.IsValid) { return(View(model)); } using (var context = new GvGenEntities()) { var entity = context.TUsers.FirstOrDefault(m => m.Email == HttpContext.User.Identity.Name && m.Password == model.OldPassword); if (entity != null) { entity.Password = model.Password; context.Entry(entity).State = System.Data.Entity.EntityState.Modified; context.SaveChanges(); ViewBag.SuccessMessage = "Your password has been changed successfully! Thank you."; } else { ModelState.AddModelError("OldPassword", "Current password incorrect."); return(View(model)); } } return(View()); }
public HttpResponseMessage SubmitPersonalInfo([FromBody] Profile profile) { var entity = profile.GetNew(); var token = Request.Headers.Authorization; if (token != null && token.Scheme.Length != 0 && token.Scheme != "null") { var id = System.Web.Security.FormsAuthentication.Decrypt(token.Scheme).UserData.Split('|')[0]; var userId = Convert.ToInt32(id); entity.IdUser = userId; } using (var db = new GvGenEntities()) { if (entity.Id > 0) { var entityEntry = db.Entry <TProfile>(entity); entityEntry.State = EntityState.Modified; } else { db.TProfiles.Add(entity); } db.SaveChanges(); } var dataReturn = new { Id = entity.Id, GuidId = entity.IdProfile }; var message = Request.CreateResponse(HttpStatusCode.OK, dataReturn); return(message); }
public HttpResponseMessage SubmitProfile([FromBody] Profile profile) { using (var db = new GvGenEntities()) { var entity = profile.GetNew(); db.TProfiles.Add(entity); db.SaveChanges(); } return(new HttpResponseMessage(HttpStatusCode.OK)); }
protected bool UpdateConvertibleModelList <T, K>(int parentId, List <T> lst) where T : IConvertibleModel <K> where K : IEntity { var newItems = GetNewItems(lst); var existedItems = GetExistedItems(lst); using (var context = new GvGenEntities()) { var set = context.Set(typeof(K)); // create new skills if (newItems != null) { foreach (var item in newItems) { set.Add(item.GetEntity()); } } // update existing skills if (existedItems != null && existedItems.Any()) { var currentItems = GetListDb(parentId, set).ToList(); //var currentItems = set.ToListAsync().Result; foreach (var item in existedItems) { var entity = currentItems.FirstOrDefault(s => (s as IEntity).Id == item.Id); if (entity == null) { return(false); } item.Update((K)entity); set.Attach(entity); DbEntityEntry entry = context.Entry(entity); entry.State = EntityState.Modified; } foreach (var entity in currentItems.ToList()) { var foundSkill = existedItems.FirstOrDefault(s => s.Id == (entity as IEntity).Id); if (foundSkill == null) { set.Attach(entity); DbEntityEntry entry = context.Entry(entity); entry.State = EntityState.Deleted; } } } context.SaveChanges(); return(true); } }