コード例 #1
0
        /// <summary>
        /// Изменить объект.
        /// </summary>
        /// <param name="entity">Объект.</param>
        public void Update(Party entity)
        {
            BusinessTripContext businessTripContext = new BusinessTripContext();

            businessTripContext.Entry(entity).State = EntityState.Modified;
            businessTripContext.SaveChanges();
        }
コード例 #2
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();
            }
        }
コード例 #3
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();
        }
コード例 #4
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();
        }
コード例 #5
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;
            }
        }
コード例 #6
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();
        }
コード例 #7
0
 /// <summary>
 /// Получение направлений по Ид командировки.
 /// </summary>
 /// <param name="businessTripId">Ид командировки.</param>
 /// <returns>Список направлений.</returns>
 public List <Direction> GetDirectionsByBusinessTripId(int businessTripId)
 {
     using (var businessTripContext = new BusinessTripContext())
     {
         return(businessTripContext.Directions.Include(l => l.Location)
                .Include(o => o.Organization).Where(d => d.BusinessTripId == businessTripId).ToList());
     }
 }
コード例 #8
0
        /// <summary>
        /// Получить все объекты.
        /// </summary>
        /// <returns>Объекты.</returns>
        public List <Core.BusinessTrip.Domain.BusinessTrip> GetAll()
        {
            BusinessTripContext businessTripContext = new BusinessTripContext(ConnectionString);

            //var ff = businessTripContext.Set<Core.BusinessTrip.Domain.BusinessTrip>().ToList();
            //businessTripContext.Database.Log = (s => System.Diagnostics.Debug.WriteLine(s));
            businessTripContext.Database.Log = (s => System.Diagnostics.Debug.WriteLine(s));
            return(businessTripContext.Set <Core.BusinessTrip.Domain.BusinessTrip>().ToList());
        }
コード例 #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
 public List <Core.BusinessTrip.Domain.BusinessTrip> GetBusinessTripFullByIds(List <int> businessTripIds)
 {
     using (var businessTripContext = new BusinessTripContext(ConnectionString))
     {
         businessTripContext.Database.Log = (s => System.Diagnostics.Debug.WriteLine(s));
         return(businessTripContext.BusinessTrips
                .Include(c => c.Command).ToList());
     }
 }
コード例 #11
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();
        }
コード例 #12
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();
        }
コード例 #13
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);
            }
        }
コード例 #14
0
        /// <summary>
        /// Получение направлений по Ид командировки.
        /// </summary>
        /// <param name="businessTripId">Ид командировки.</param>
        /// <returns>Список направлений.</returns>
        public List <Direction> GetDirectionsByBusinessTripId(int businessTripId)
        {
            using (var businessTripContext = new BusinessTripContext(ConnectionString))
            {
                businessTripContext.Database.Log = (s => System.Diagnostics.Debug.WriteLine(s));

                return(businessTripContext.Directions.Include(l => l.Location)
                       .Include(o => o.Organization).Where(d => d.BusinessTripId == businessTripId).ToList());
            }
        }
コード例 #15
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);
            }
        }
コード例 #16
0
 public List <PartyPerson> GetPartyPersonsByPartyId(int partyId)
 {
     using (var businessTripContext = new BusinessTripContext(ConnectionString))
     {
         businessTripContext.Database.Log = (s => System.Diagnostics.Debug.WriteLine(s));
         return(businessTripContext.PartysPersons
                .Include(p => p.Party)
                .Include(p => p.Person)
                .Include(p => p.Person.Position)
                .Include(p => p.Person.Department).Where(p => p.Party_PartyId == partyId).ToList());
     }
 }
コード例 #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 businessTripContex = new BusinessTripContext())
     {
         foreach (var directionId in directionIds)
         {
             var direction = new Direction
             {
                 DirectionId = directionId
             };
             businessTripContex.Directions.Attach(direction);
             businessTripContex.Directions.Remove(direction);
         }
         businessTripContex.SaveChanges();
     }
 }
コード例 #19
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;
        }
コード例 #20
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();
     }
 }
コード例 #21
0
        public Dictionary <string, string> GetTargetsByReasons(List <string> reasons)
        {
            using (var businessTripContext = new BusinessTripContext("Server=as21430; Initial Catalog=ContractsPIR; Integrated Security = True;", true))
            {
                if (reasons.Count == 0)
                {
                    return(null);
                }

                var sqlString = string.Format("Select [CodeProjectP] AS [Code],[NameProject] AS [Target] From [Table_ContractsPIR] Where [CodeProjectP] in ({0})",
                                              string.Join(", ", reasons.Distinct().Select(a => string.Format("'{0}'", a))));

                businessTripContext.Database.Log = (s => System.Diagnostics.Debug.WriteLine(s));

                return(businessTripContext.Database.SqlQuery <ContractPIR>(sqlString).ToDictionary(c => c.Code, c => c.Target.TrimStart(' ').TrimEnd(' ')));
            }
        }
コード例 #22
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();
        }
コード例 #23
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();
            }
        }
コード例 #24
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);
            }
        }
コード例 #25
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();
            }
        }
コード例 #26
0
 public ApplicationsController(BusinessTripContext context)
 {
     _context = context;
 }
コード例 #27
0
        /// <summary>
        /// Получить все объекты.
        /// </summary>
        /// <returns>Объекты.</returns>
        public List <Party> GetAll()
        {
            BusinessTripContext businessTripContext = new BusinessTripContext();

            return(businessTripContext.Set <Party>().ToList());
        }
コード例 #28
0
 public ProjectsController(BusinessTripContext context)
 {
     _context = context;
 }
コード例 #29
0
        /// <summary>
        /// Получить все объекты.
        /// </summary>
        /// <returns>Объекты.</returns>
        public List <Core.BusinessTrip.Domain.BusinessTrip> GetAll()
        {
            BusinessTripContext businessTripContext = new BusinessTripContext();

            return(businessTripContext.Set <Core.BusinessTrip.Domain.BusinessTrip>().ToList());
        }
コード例 #30
0
 public AccountController(BusinessTripContext _db)
 {
     db = _db;
 }