//відредагувати дані користувача public async Task <IActionResult> Edit(EditUserViewModel model) { if (ModelState.IsValid) { User user = await _db.User.FirstOrDefaultAsync(u => u.Id == model.Id); if (user != null) { user.FirstName = model.FirstName; user.FatherName = model.FatherName; user.LastName = model.LastName; _db.User.Update(user); try { _db.SaveChanges(); } catch (Exception e) { ModelState.AddModelError(string.Empty, e.Message); } if (((ClaimsIdentity)User.Identity).Claims .Where(c => c.Type == ClaimTypes.Role) .Select(c => c.Value).Where(r => r == "admin").Count() != 0) { return(RedirectToAction("UsersList"));; } else { return(RedirectToAction("Index")); } } } return(View(model)); }
/// <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; } }
/// <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(); } }
/// <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="businessTrip">Командировка.</param> /// <param name="DirectionIds">Ид направлений.</param> public void SaveParty(Party party, List <int> personIds) { using (var businessTripContex = new BusinessTripContext()) { businessTripContex.Partys.Add(party); businessTripContex.SaveChanges(); foreach (var personId in personIds) { businessTripContex.PartysPersons.Add(new PartyPerson { Party_PartyId = party.PartyId, Person_PersonId = personId }); } businessTripContex.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 <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="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="businessTrip">Командировка.</param> /// <returns>Ид новой командировки.</returns> public int SaveBusinessTrip(Core.BusinessTrip.Domain.BusinessTrip businessTrip) { using (var businessTripContex = new BusinessTripContext()) { businessTripContex.BusinessTrips.Add(businessTrip); businessTripContex.SaveChanges(); return(businessTrip.BusinessTripId); } }
/// <summary> /// Сохранение командировки. /// </summary> /// <param name="businessTrip">Командировка.</param> public Core.BusinessTrip.Domain.BusinessTrip SaveBusinessTrip(Core.BusinessTrip.Domain.BusinessTrip businessTrip) { using (var businessTripContext = new BusinessTripContext(ConnectionString)) { businessTripContext.BusinessTrips.Add(businessTrip); businessTripContext.Database.Log = (s => System.Diagnostics.Debug.WriteLine(s)); businessTripContext.SaveChanges(); return(businessTrip); } }
/// <summary> /// Сохранение партии. /// </summary> /// <param name="party">Партия.</param> /// <param name="persons">Список сотрудников.</param> public Party SaveParty(Party party, List <PartyPerson> persons) { using (var businessTripContex = new BusinessTripContext(ConnectionString)) { businessTripContex.Partys.Add(party); businessTripContex.SaveChanges(); foreach (var person in persons) { businessTripContex.PartysPersons.Add(new PartyPerson { Party_PartyId = party.PartyId, Person_PersonId = person.Person_PersonId, IsResponsible = person.IsResponsible }); } businessTripContex.SaveChanges(); return(party); } }
/// <summary> /// Удаление направлений по Ид. /// </summary> /// <param name="directionIds">Ид направлений.</param> public void DeleteDirectionByIds(List <int> directionIds) { using (var businessTripContex = new BusinessTripContext()) { foreach (var directionId in directionIds) { var direction = new Direction { DirectionId = directionId }; businessTripContex.Directions.Attach(direction); businessTripContex.Directions.Remove(direction); } businessTripContex.SaveChanges(); } }
/// <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; }
/// <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="directionIds">Ид направлений.</param> public void DeleteDirectionByIds(List <int> directionIds) { using (var businessTripContext = new BusinessTripContext(ConnectionString)) { foreach (var directionId in directionIds) { var direction = new Direction { DirectionId = directionId }; businessTripContext.Directions.Attach(direction); businessTripContext.Directions.Remove(direction); } businessTripContext.Database.Log = (s => System.Diagnostics.Debug.WriteLine(s)); 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="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(); } }
//Видалення заявки користувачем public IActionResult Delete(int id) { Application request = _context.Application.Find(id); // получаем текущего пользователя User user = _context.User.Where(m => m.Email == HttpContext.User.Identity.Name).First(); if (request != null && request.UserId == user.Id && request.Status != 2 && request.Status != 3) { Lifecycle lifecycle = _context.Lifecycle.Find(request.LifecycleId); _context.Lifecycle.Remove(lifecycle); _context.SaveChanges(); } else if (request != null && user.RoleId == 1) { Lifecycle lifecycle = _context.Lifecycle.Find(request.LifecycleId); _context.Lifecycle.Remove(lifecycle); _context.SaveChanges(); return(RedirectToAction("RequestList")); } return(RedirectToAction("Index")); }