コード例 #1
0
        //відредагувати дані користувача
        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));
        }
コード例 #2
0
        /// <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;
            }
        }
コード例 #3
0
        /// <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();
            }
        }
コード例 #4
0
        /// <summary>
        /// Изменить объект.
        /// </summary>
        /// <param name="entity">Объект.</param>
        public void Update(Party entity)
        {
            BusinessTripContext businessTripContext = new BusinessTripContext();

            businessTripContext.Entry(entity).State = EntityState.Modified;
            businessTripContext.SaveChanges();
        }
コード例 #5
0
        /// <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();
        }
コード例 #6
0
        /// <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();
        }
コード例 #7
0
        /// <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();
        }
コード例 #8
0
        /// <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();
            }
        }
コード例 #9
0
        /// <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);
        }
コード例 #10
0
        /// <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();
        }
コード例 #11
0
        /// <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();
        }
コード例 #12
0
        /// <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);
            }
        }
コード例 #13
0
        /// <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);
            }
        }
コード例 #14
0
        /// <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);
            }
        }
コード例 #15
0
 /// <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();
     }
 }
コード例 #16
0
        /// <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;
        }
コード例 #17
0
        /// <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);
        }
コード例 #18
0
 /// <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();
     }
 }
コード例 #19
0
        /// <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();
        }
コード例 #20
0
        /// <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();
            }
        }
コード例 #21
0
        //Видалення заявки користувачем

        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"));
        }