Exemple #1
0
        private Software CreateModel(SoftwareBindingModel model, Software software)
        {
            software.Name        = model.Name;
            software.LicenseType = model.License_type;

            return(software);
        }
Exemple #2
0
 public void Insert(SoftwareBindingModel model)
 {
     using (var context = new ComputingEquipmentDatabase())
     {
         context.Software.Add(CreateModel(model, new Software()));
         context.SaveChanges();
     }
 }
Exemple #3
0
        public void Delete(SoftwareBindingModel model)
        {
            var element = softwareStorage.GetElement(new SoftwareBindingModel {
                Id = model.Id
            });

            if (element == null)
            {
                throw new Exception("Элемент не найден");
            }
            softwareStorage.Delete(model);
        }
Exemple #4
0
        public void Update(SoftwareBindingModel model)
        {
            using (var context = new ComputingEquipmentDatabase())
            {
                var software = context.Software.FirstOrDefault(rec => rec.Id == model.Id);

                if (software == null)
                {
                    throw new Exception("ПО не найдено");
                }
                CreateModel(model, software);
                context.SaveChanges();
            }
        }
Exemple #5
0
 public List <SoftwareViewModel> Read(SoftwareBindingModel model)
 {
     if (model == null)
     {
         return(softwareStorage.GetFullList());
     }
     if (model.Id.HasValue)
     {
         return(new List <SoftwareViewModel> {
             softwareStorage.GetElement(model)
         });
     }
     return(softwareStorage.GetFilteredList(model));
 }
Exemple #6
0
        public void CreateOrUpdate(SoftwareBindingModel model)
        {
            var element = softwareStorage.GetElement(new SoftwareBindingModel {
                Id = model.Id
            });

            if (element != null)
            {
                softwareStorage.Update(model);
            }
            else
            {
                softwareStorage.Insert(model);
            }
        }
Exemple #7
0
        public void Delete(SoftwareBindingModel model)
        {
            using (var context = new ComputingEquipmentDatabase())
            {
                Software software = context.Software.FirstOrDefault(rec => rec.Id == model.Id);

                if (software != null)
                {
                    context.Software.Remove(software);
                    context.SaveChanges();
                }
                else
                {
                    throw new Exception("ПО не найдено");
                }
            }
        }
Exemple #8
0
        public List <SoftwareViewModel> GetFilteredList(SoftwareBindingModel model)
        {
            if (model == null)
            {
                return(null);
            }

            using (var context = new ComputingEquipmentDatabase())
            {
                return(context.Software
                       .Where(rec => rec.LicenseType == model.License_type)
                       .Select(rec => new SoftwareViewModel
                {
                    Id = rec.Id,
                    Name = rec.Name,
                    License_type = rec.LicenseType
                }).ToList());
            }
        }
Exemple #9
0
        public SoftwareViewModel GetElement(SoftwareBindingModel model)
        {
            if (model == null)
            {
                return(null);
            }

            using (var context = new ComputingEquipmentDatabase())
            {
                var software = context.Software
                               .FirstOrDefault(rec => rec.Id == model.Id);
                return(software != null ?
                       new SoftwareViewModel
                {
                    Id = software.Id,
                    Name = software.Name,
                    License_type = software.LicenseType
                } : null);
            }
        }