public ActionResult EditServices(ProfilingModel model) { if (model == null) { return(View("ProfilePage")); } UserService service = new UserService(); service.Id = model.Id; service.ServiceName = model.ServiceName; service.ServiceDescription = model.ServiceDes; service.UserId = User.Identity.GetUserId(); service.Images = model.serviceImages; service.FullAddress = model.HomeAddress; try { serviceContext.Entry(service).State = EntityState.Modified; serviceContext.SaveChanges(); //serviceContext.UserServices.Attach(service); //serviceContext.Entry(service).Property(x => x.ServiceName).IsModified = true; //serviceContext.Entry(service).Property(x => x.ServiceDescription).IsModified = true; //serviceContext.Entry(service).Property(x=>x.UserId).IsModified=true; //if (!string.IsNullOrEmpty(model.serviceImages)) //{ // serviceContext.Entry(service).Property(x => x.Images).IsModified = true; //} //serviceContext.SaveChanges(); Session["Success"] = "Edited Sucessfully"; } catch (System.Data.Entity.Validation.DbEntityValidationException dbEx) { Exception raise = dbEx; foreach (var validationErrors in dbEx.EntityValidationErrors) { foreach (var validationError in validationErrors.ValidationErrors) { string message = string.Format("{0}:{1}", validationErrors.Entry.Entity.ToString(), validationError.ErrorMessage); // raise a new exception nesting // the current instance as InnerException raise = new InvalidOperationException(message, raise); } } throw raise; } return(RedirectToAction("ProfilePage")); }
public IHttpActionResult Put([FromUri] string section, [FromBody] Sections SectionEntity) { using (ServicesEntities db = new ServicesEntities()) { try { var UpdatedEntity = db.Sections.Where(s => s.Section == section).FirstOrDefault(); if (UpdatedEntity != null) { UpdatedEntity.City = SectionEntity.City; UpdatedEntity.Location = SectionEntity.Location; UpdatedEntity.Name = SectionEntity.Name; db.Entry(UpdatedEntity).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); return(Ok()); } else { return(BadRequest("Записи с данным идентификатором сервера не найдено.")); } } catch (Exception ex) { return(BadRequest(ex.ToString())); } } }
public void insertRegCode(string userId, int regCode) { var query = from uprofile in serviceContext.Users where uprofile.UserId == userId select uprofile; var q = query.SingleOrDefault(); q.RegCode = regCode.ToString(); try { serviceContext.Entry(q).State = EntityState.Modified; serviceContext.SaveChanges(); } catch { throw; } }