/// <summary> /// Изменить объект. /// </summary> /// <param name="entity">Объект.</param> public void Update(Core.BusinessTrip.Domain.BusinessTrip entity) { using (BusinessTripContext businessTripContext = new BusinessTripContext(ConnectionString)) { businessTripContext.Configuration.AutoDetectChangesEnabled = false; businessTripContext.Configuration.ValidateOnSaveEnabled = false; var com = entity.Command; com.BusinessTripId = entity.BusinessTripId; businessTripContext.Entry <Command>(com).State = EntityState.Modified; entity.Command = null; var requestTransport = entity.RequestTransport; requestTransport.BusinessTripId = entity.BusinessTripId; businessTripContext.Entry <RequestTransport>(requestTransport).State = EntityState.Modified; entity.RequestTransport = null; businessTripContext.Entry <Core.BusinessTrip.Domain.BusinessTrip>(entity).State = EntityState.Modified; businessTripContext.Database.Log = (s => System.Diagnostics.Debug.WriteLine(s)); businessTripContext.SaveChanges(); businessTripContext.Configuration.AutoDetectChangesEnabled = true; businessTripContext.Configuration.ValidateOnSaveEnabled = true; } }
public ActionResult ChangeStatus(int requestId, int status) { User user = _context.User.Where(m => m.Email == HttpContext.User.Identity.Name).First(); if (user == null) { return(NotFound()); } Application req = _context.Application.Find(requestId); if (req != null) { req.Status = status; Lifecycle lifecycle = _context.Lifecycle.Find(req.LifecycleId); if (status == (int)RequestStatus.Checking) { lifecycle.Checking = DateTime.Now; } else if (status == (int)RequestStatus.Closed) { lifecycle.Closed = DateTime.Now; } else if (status == (int)RequestStatus.Rejected) { lifecycle.Closed = DateTime.Now; } _context.Entry(lifecycle).State = EntityState.Modified; _context.Entry(req).State = EntityState.Modified; _context.SaveChanges(); } return(RedirectToAction("ChangeStatus")); }
/// <summary> /// Редактирование командировки. /// </summary> /// <param name="businessTrip">Командировка.</param> /// <param name="AddDirectionIds">Ид новых направлений у командировки.</param> /// <param name="DeleteDirectionIds">Ид направлений, которые необходимо удалить.</param> public void UpdateParty(Party party, List <int> addPersonIds, List <int> deletePersonIds) { using (var businessTripContex = new BusinessTripContext()) { businessTripContex.Entry(party).State = EntityState.Modified; foreach (var personId in deletePersonIds) { var partyPerson = new PartyPerson { Party_PartyId = party.PartyId, Person_PersonId = personId }; businessTripContex.Entry(partyPerson).State = EntityState.Deleted; } foreach (var personId in addPersonIds) { var partyPerson = new PartyPerson { Party_PartyId = party.PartyId, Person_PersonId = personId }; businessTripContex.Entry(partyPerson).State = EntityState.Added; } businessTripContex.SaveChanges(); } }
public async Task <IActionResult> PutProject([FromRoute] int id, [FromBody] Project project) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != project.ProjectId) { return(BadRequest()); } _context.Entry(project).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ProjectExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <IActionResult> PutEmployeeBase([FromRoute] int id, [FromBody] EmployeeBase employeeBase) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != employeeBase.EmployeeBaseId) { return(BadRequest()); } _context.Entry(employeeBase).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!EmployeeBaseExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
/// <summary> /// Изменить объект. /// </summary> /// <param name="entity">Объект.</param> public void Update(Party entity) { BusinessTripContext businessTripContext = new BusinessTripContext(); businessTripContext.Entry(entity).State = EntityState.Modified; businessTripContext.SaveChanges(); }
/// <summary> /// Сохранить объект. /// </summary> /// <param name="entity">Объект.</param> public void Save(Core.BusinessTrip.Domain.BusinessTrip entity) { BusinessTripContext businessTripContext = new BusinessTripContext(); businessTripContext.Entry(entity).State = EntityState.Added; businessTripContext.SaveChanges(); }
/// <summary> /// Изменить объект. /// </summary> /// <param name="entity">Объект.</param> public void Update(Core.BusinessTrip.Domain.BusinessTrip entity) { BusinessTripContext businessTripContext = new BusinessTripContext(); businessTripContext.Entry <Core.BusinessTrip.Domain.BusinessTrip>(entity).State = EntityState.Modified; businessTripContext.SaveChanges(); }
/// <summary> /// Изменить объект. /// </summary> /// <param name="entity">Объект.</param> public void Update(TEntity entity) { BusinessTripContext businessTripContext = new BusinessTripContext(ConnectionString); businessTripContext.Entry <TEntity>(entity).State = EntityState.Modified; businessTripContext.SaveChanges(); }
/// <summary> /// Удалить объекты. /// </summary> /// <param name="entities">Объекты.</param> public void Delete(List <Core.BusinessTrip.Domain.BusinessTrip> entities) { BusinessTripContext businessTripContext = new BusinessTripContext(ConnectionString); foreach (Core.BusinessTrip.Domain.BusinessTrip entity in entities) { businessTripContext.Entry <Command>(new Command { BusinessTripId = entity.BusinessTripId }).State = EntityState.Deleted; businessTripContext.Entry <RequestTransport>(new RequestTransport { BusinessTripId = entity.BusinessTripId }).State = EntityState.Deleted; businessTripContext.Entry <Core.BusinessTrip.Domain.BusinessTrip>(entity).State = EntityState.Deleted; } businessTripContext.Database.Log = (s => System.Diagnostics.Debug.WriteLine(s)); businessTripContext.SaveChanges(); }
/// <summary> /// Сохранить объект. /// </summary> /// <param name="entity">Объект.</param> public Party Save(Party entity) { BusinessTripContext businessTripContext = new BusinessTripContext(ConnectionString); businessTripContext.Entry(entity).State = EntityState.Added; businessTripContext.SaveChanges(); return(entity); }
/// <summary> /// Удалить объекты. /// </summary> /// <param name="entities">Объекты.</param> public void Delete(List <Party> entities) { BusinessTripContext businessTripContext = new BusinessTripContext(); foreach (Party entity in entities) { businessTripContext.Entry(entity).State = EntityState.Deleted; } businessTripContext.SaveChanges(); }
/// <summary> /// Удалить объекты. /// </summary> /// <param name="entities">Объекты.</param> public void Delete(List <Core.BusinessTrip.Domain.BusinessTrip> entities) { BusinessTripContext businessTripContext = new BusinessTripContext(); foreach (Core.BusinessTrip.Domain.BusinessTrip entity in entities) { businessTripContext.Entry <Core.BusinessTrip.Domain.BusinessTrip>(entity).State = EntityState.Deleted; } businessTripContext.SaveChanges(); }
/// <summary> /// Обновление партии. /// </summary> /// <param name="party">Партия.</param> /// <param name="addPersons">Новые сотрудники в партии.</param> /// <param name="deletePersons">Сотрудники в партии к удалению.</param> /// <param name="editPersons">Сотрудники в партии для редактирования.</param> public void UpdateParty(Party party, List <PartyPerson> addPersons, List <PartyPerson> deletePersons, List <PartyPerson> editPersons) { using (var businessTripContex = new BusinessTripContext(ConnectionString)) { businessTripContex.Entry(party).State = EntityState.Modified; foreach (var person in deletePersons) { businessTripContex.Entry(person).State = EntityState.Deleted; //var partyPerson = new PartyPerson //{ // Party_PartyId = party.PartyId, // Person_PersonId = personId //}; //businessTripContex.Entry(partyPerson).State = EntityState.Deleted; } foreach (var person in addPersons) { businessTripContex.Entry(person).State = EntityState.Added; //var partyPerson = new PartyPerson //{ // Party_PartyId = party.PartyId, // Person_PersonId = person.Key, // IsResponsible = person.Value //}; //businessTripContex.Entry(partyPerson).State = EntityState.Added; } foreach (var person in editPersons) { businessTripContex.Entry(person).State = EntityState.Modified; } businessTripContex.SaveChanges(); } }
/// <summary> /// Сохранить объект. /// </summary> /// <param name="entity">Объект.</param> public Core.BusinessTrip.Domain.BusinessTrip Save(Core.BusinessTrip.Domain.BusinessTrip entity) { BusinessTripContext businessTripContext = new BusinessTripContext(ConnectionString); businessTripContext.Configuration.AutoDetectChangesEnabled = false; businessTripContext.Configuration.ValidateOnSaveEnabled = false; businessTripContext.Entry(entity).State = EntityState.Added; businessTripContext.Database.Log = (s => System.Diagnostics.Debug.WriteLine(s)); businessTripContext.SaveChanges(); businessTripContext.Configuration.AutoDetectChangesEnabled = true; businessTripContext.Configuration.ValidateOnSaveEnabled = true; return(entity); }
/// <summary> /// Удалить объекты. /// </summary> /// <param name="entities">Объекты.</param> public void Delete(List <TEntity> entities) { BusinessTripContext businessTripContext = new BusinessTripContext(); businessTripContext.Configuration.AutoDetectChangesEnabled = false; businessTripContext.Configuration.ValidateOnSaveEnabled = false; foreach (TEntity entity in entities) { businessTripContext.Entry <TEntity>(entity).State = EntityState.Deleted; } businessTripContext.SaveChanges(); businessTripContext.Configuration.AutoDetectChangesEnabled = true; businessTripContext.Configuration.ValidateOnSaveEnabled = true; }
public IActionResult EditRole(int userId, int roleId) { User user = _db.User.Where(m => m.Email == HttpContext.User.Identity.Name).First(); if (user == null) { return(NotFound()); } User user1 = _db.User.Find(userId); if (user1 != null) { user1.RoleId = roleId; _db.Entry(user1).State = EntityState.Modified; _db.SaveChanges(); } return(RedirectToAction("EditRole")); }