Beispiel #1
0
        internal void Update(int id, User model)
        {
            using (var Entities = new CCLMEntities())
            {
                var userEntity = Entities.users.FirstOrDefault(x => x.id == id);
                if (userEntity == null)
                {
                    throw new Exception("Usuario no encontrado");
                }

                var ids           = userEntity.distribution_centers.Select(x => x.id).ToList();
                var oldDsEntities = Entities.distribution_centers.Where(x => ids.Contains(x.id));

                foreach (var ds in oldDsEntities)
                {
                    userEntity.distribution_centers.Remove(ds);
                }

                var newDsEntities = Entities.distribution_centers.Where(x => model.DistributionCentersSelected.Contains(x.id));
                foreach (var ds in newDsEntities)
                {
                    userEntity.distribution_centers.Add(ds);
                }

                Entities.SaveChanges();
            }
        }
Beispiel #2
0
 internal void Create(User model)
 {
     using (var Entities = new CCLMEntities())
     {
         Entities.users.Add(new users
         {
             nickname             = model.NickName,
             full_name            = model.FullName,
             email                = model.Email,
             is_full              = model.IsFull,
             distribution_centers = GenerateDS(Entities, model.DistributionCentersSelected)
         });
         Entities.SaveChanges();
     }
 }
 internal List <DistributionCenter> GetAll()
 {
     using (var Entities = new CCLMEntities())
     {
         return(Entities.distribution_centers.Select(x => new DistributionCenter
         {
             Id = x.id,
             Code = x.code.Value,
             Name = x.name,
             ProcessEndTime = x.process_end_time.Value,
             ProcessStartTime = x.process_start_time.Value,
             BinnacleDays = x.binnacle_days.Value
         }).ToList());
     }
 }
 internal void Create(DistributionCenter model)
 {
     using (var Entities = new CCLMEntities())
     {
         Entities.distribution_centers.Add(new distribution_centers
         {
             code = model.Code,
             name = model.Name,
             process_start_time = model.ProcessStartTime,
             process_end_time   = model.ProcessEndTime,
             binnacle_days      = model.BinnacleDays,
             mail_success       = false
         });
         Entities.SaveChanges();
     }
 }
        internal void Update(int Id, DistributionCenter model)
        {
            using (var Entities = new CCLMEntities())
            {
                var dsEntity = Entities.distribution_centers.FirstOrDefault(x => x.id == Id);
                if (dsEntity == null)
                {
                    throw new Exception("Sitio no encontrado");
                }

                dsEntity.name = model.Name;
                dsEntity.process_start_time = model.ProcessStartTime;
                dsEntity.process_end_time   = model.ProcessEndTime;
                dsEntity.binnacle_days      = model.BinnacleDays;

                Entities.SaveChanges();
            }
        }
 internal DistributionCenter Get(int?Id)
 {
     using (var Entities = new CCLMEntities())
     {
         var dsEntity = Entities.distribution_centers.FirstOrDefault(x => x.id == Id.Value);
         if (dsEntity == null)
         {
             throw new Exception("Sitio no encontrado");
         }
         return(new DistributionCenter
         {
             Id = dsEntity.id,
             Code = dsEntity.code.Value,
             Name = dsEntity.name,
             ProcessStartTime = dsEntity.process_start_time.Value,
             ProcessEndTime = dsEntity.process_end_time.Value,
             BinnacleDays = dsEntity.binnacle_days.Value
         });
     }
 }
Beispiel #7
0
 internal User Get(int?Id)
 {
     using (var Entities = new CCLMEntities())
     {
         var userEntity = Entities.users.FirstOrDefault(x => x.id == Id.Value);
         if (userEntity == null)
         {
             throw new Exception("Usuario no encontrado");
         }
         return(new User
         {
             Id = userEntity.id,
             Email = userEntity.email,
             FullName = userEntity.full_name,
             NickName = userEntity.nickname,
             IsFull = userEntity.is_full.Value,
             DistributionCentersSelected = userEntity.distribution_centers.Select(y => y.id).ToList(),
             DistributionCentersAmount = userEntity.distribution_centers.Count(),
             //DistributionCenters = userEntity.distribution_centers.Select(y => new DistributionCenter { Id = y.id, Code = y.code.Value, Name = y.name }).ToList()
         });
     }
 }
Beispiel #8
0
 internal List <User> GetAll()
 {
     using (var Entities = new CCLMEntities())
     {
         List <User> users = new List <User>();
         foreach (var user in Entities.users)
         {
             users.Add(new User
             {
                 Id       = user.id,
                 Email    = user.email,
                 FullName = user.full_name,
                 NickName = user.nickname,
                 IsFull   = user.is_full.Value,
                 DistributionCentersSelected = user.distribution_centers.Select(y => y.id).ToList(),
                 DistributionCentersAmount   = user.distribution_centers.Count(),
                 //DistributionCenters=user.distribution_centers.Select(y => new DistributionCenter { Id = y.id, Code = y.code.Value, Name = y.name }).ToList()
             });
         }
         return(users);
     }
 }
Beispiel #9
0
 private ICollection <distribution_centers> GenerateDS(CCLMEntities Entities, List <int> DSIds)
 {
     return(Entities.distribution_centers.Where(x => DSIds.Contains(x.id)).ToList());
 }