public void CreateOrUpdate(EquipmentSoftwareBindingModel model)
        {
            var element = eqSoftStorage.GetElement(new EquipmentSoftwareBindingModel {
                Id = model.Id
            });

            var list = eqSoftStorage.GetFilteredList(new EquipmentSoftwareBindingModel
            {
                EquipmentId = model.EquipmentId,
                SoftwareId  = model.SoftwareId
            });

            if (list != null && list[0].Id != model.Id)
            {
                throw new Exception("Данное ПО уже установлено на выбранный образец вычислительной техники");
            }

            if (element != null)
            {
                eqSoftStorage.Update(model);
            }
            else
            {
                eqSoftStorage.Insert(model);
            }
        }
示例#2
0
        public EquipmentSoftwareViewModel GetElement(EquipmentSoftwareBindingModel model)
        {
            if (model == null)
            {
                return(null);
            }

            using (var context = new ComputingEquipmentDatabase())
            {
                var eqSoft = context.EquipmentSoftware
                             .Include(rec => rec.Software)
                             .Include(rec => rec.Equipment)
                             .ThenInclude(rec => rec.Type)
                             .FirstOrDefault(rec => rec.Id == model.Id);
                return(eqSoft != null ?
                       new EquipmentSoftwareViewModel
                {
                    Id = eqSoft.Id,
                    SoftwareId = eqSoft.SoftwareId,
                    EquipmentId = eqSoft.EquipmentId,
                    SoftwareName = eqSoft.Software.Name,
                    EquipmentName = eqSoft.Equipment.Name,
                    EquipmentType = eqSoft.Equipment.Type.Name
                } : null);
            }
        }
示例#3
0
        public List <EquipmentSoftwareViewModel> GetFilteredList(EquipmentSoftwareBindingModel model)
        {
            if (model == null)
            {
                return(null);
            }

            using (var context = new ComputingEquipmentDatabase())
            {
                return(context.EquipmentSoftware
                       .Include(rec => rec.Software)
                       .Include(rec => rec.Equipment)
                       .ThenInclude(rec => rec.Type)
                       .Where(rec => !string.IsNullOrEmpty(model.EquipmentName) && rec.Equipment.Name.Contains(model.EquipmentName))
                       .Select(rec => new EquipmentSoftwareViewModel
                {
                    Id = rec.Id,
                    EquipmentId = rec.EquipmentId,
                    SoftwareId = rec.SoftwareId,
                    EquipmentName = rec.Equipment.Name,
                    SoftwareName = rec.Software.Name,
                    EquipmentType = rec.Equipment.Type.Name
                }).ToList());
            }
        }
示例#4
0
        private EquipmentSoftware CreateModel(EquipmentSoftwareBindingModel model, EquipmentSoftware eqSoft)
        {
            eqSoft.SoftwareId  = model.SoftwareId;
            eqSoft.EquipmentId = model.EquipmentId;

            return(eqSoft);
        }
示例#5
0
 public void Insert(EquipmentSoftwareBindingModel model)
 {
     using (var context = new ComputingEquipmentDatabase())
     {
         context.EquipmentSoftware.Add(CreateModel(model, new EquipmentSoftware()));
         context.SaveChanges();
     }
 }
        public void Delete(EquipmentSoftwareBindingModel model)
        {
            var element = eqSoftStorage.GetElement(new EquipmentSoftwareBindingModel {
                Id = model.Id
            });

            if (element == null)
            {
                throw new Exception("Элемент не найден");
            }
            eqSoftStorage.Delete(model);
        }
 public List <EquipmentSoftwareViewModel> Read(EquipmentSoftwareBindingModel model)
 {
     if (model == null)
     {
         return(eqSoftStorage.GetFullList());
     }
     if (model.Id.HasValue)
     {
         return(new List <EquipmentSoftwareViewModel> {
             eqSoftStorage.GetElement(model)
         });
     }
     return(eqSoftStorage.GetFilteredList(model));
 }
示例#8
0
        public void Update(EquipmentSoftwareBindingModel model)
        {
            using (var context = new ComputingEquipmentDatabase())
            {
                var eqSoft = context.EquipmentSoftware.FirstOrDefault(rec => rec.Id == model.Id);

                if (eqSoft == null)
                {
                    throw new Exception("Данная пара \"Техника - ПО\" не найдена");
                }
                CreateModel(model, eqSoft);
                context.SaveChanges();
            }
        }
示例#9
0
        public void Delete(EquipmentSoftwareBindingModel model)
        {
            using (var context = new ComputingEquipmentDatabase())
            {
                EquipmentSoftware eqSoft = context.EquipmentSoftware.FirstOrDefault(rec => rec.Id == model.Id);

                if (eqSoft != null)
                {
                    context.EquipmentSoftware.Remove(eqSoft);
                    context.SaveChanges();
                }
                else
                {
                    throw new Exception("Данная пара \"Техника - ПО\" не найдена");
                }
            }
        }