public void Insert(SupplierBindingModel model)
 {
     using (var context = new ComputingEquipmentDatabase())
     {
         context.Supplier.Add(CreateModel(model, new Supplier()));
         context.SaveChanges();
     }
 }
        private Supplier CreateModel(SupplierBindingModel model, Supplier supplier)
        {
            supplier.OrganizationName = model.OrganizationName;
            supplier.EmployeeName     = model.EmployeeName;
            supplier.Address          = model.Address;
            supplier.PhoneNumber      = model.PhoneNumber;

            return(supplier);
        }
Exemple #3
0
        public void Delete(SupplierBindingModel model)
        {
            var element = supplierStorage.GetElement(new SupplierBindingModel {
                Id = model.Id
            });

            if (element == null)
            {
                throw new Exception("Элемент не найден");
            }
            supplierStorage.Delete(model);
        }
        public void Update(SupplierBindingModel model)
        {
            using (var context = new ComputingEquipmentDatabase())
            {
                var supplier = context.Supplier.FirstOrDefault(rec => rec.Id == model.Id);

                if (supplier == null)
                {
                    throw new Exception("Поставщик не найден");
                }
                CreateModel(model, supplier);
                context.SaveChanges();
            }
        }
Exemple #5
0
 public List <SupplierViewModel> Read(SupplierBindingModel model)
 {
     if (model == null)
     {
         return(supplierStorage.GetFullList());
     }
     if (model.Id.HasValue)
     {
         return(new List <SupplierViewModel> {
             supplierStorage.GetElement(model)
         });
     }
     return(supplierStorage.GetFilteredList(model));
 }
Exemple #6
0
        public void CreateOrUpdate(SupplierBindingModel model)
        {
            var element = supplierStorage.GetElement(new SupplierBindingModel {
                Id = model.Id
            });

            if (element != null)
            {
                supplierStorage.Update(model);
            }
            else
            {
                supplierStorage.Insert(model);
            }
        }
        public async Task <bool> AddSupplierAsync(SupplierBindingModel model)
        {
            if (string.IsNullOrEmpty(model.Name) ||
                this.context.Suppliers.FirstOrDefault(sup => sup.Name == model.Name) != null)
            {
                return(false);
            }

            var supplier = this.mapper.Map <Supplier>(model);

            this.context.Suppliers.Add(supplier);
            await this.context.SaveChangesAsync();

            return(await this.context.Suppliers.ContainsAsync(supplier));
        }
        public void Delete(SupplierBindingModel model)
        {
            using (var context = new ComputingEquipmentDatabase())
            {
                Supplier supplier = context.Supplier.FirstOrDefault(rec => rec.Id == model.Id);

                if (supplier != null)
                {
                    context.Supplier.Remove(supplier);
                    context.SaveChanges();
                }
                else
                {
                    throw new Exception("Поставщик не найден");
                }
            }
        }
        public async Task <IActionResult> AddSupplier(SupplierBindingModel model)
        {
            if (!this.ModelState.IsValid)
            {
                return(this.View(model));
            }

            var action = await this.fitnessService.AddSupplierAsync(model);

            if (!action)
            {
                this.ViewData["Errors"] = GlobalConstants.SameSupplierErrorMessage;
                return(this.View(model));
            }

            var suppliers = await this.fitnessService.GetAllSuppliersAsync();

            return(this.View("SuppliersAll", suppliers));
        }
        public SupplierViewModel GetElement(SupplierBindingModel model)
        {
            if (model == null)
            {
                return(null);
            }

            using (var context = new ComputingEquipmentDatabase())
            {
                var supplier = context.Supplier
                               .FirstOrDefault(rec => rec.Id == model.Id);
                return(supplier != null ?
                       new SupplierViewModel
                {
                    Id = supplier.Id,
                    OrganizationName = supplier.OrganizationName,
                    EmployeeName = supplier.EmployeeName,
                    Address = supplier.Address,
                    PhoneNumber = supplier.PhoneNumber
                } : null);
            }
        }
        public List <SupplierViewModel> GetFilteredList(SupplierBindingModel model)
        {
            if (model == null)
            {
                return(null);
            }

            using (var context = new ComputingEquipmentDatabase())
            {
                return(context.Supplier
                       .Where(rec => !string.IsNullOrEmpty(model.OrganizationName) && rec.OrganizationName.Contains(model.OrganizationName) ||
                              !string.IsNullOrEmpty(model.Address) && rec.Address.Contains(model.Address))
                       .Select(rec => new SupplierViewModel
                {
                    Id = rec.Id,
                    OrganizationName = rec.OrganizationName,
                    EmployeeName = rec.EmployeeName,
                    Address = rec.Address,
                    PhoneNumber = rec.PhoneNumber
                }).ToList());
            }
        }
        public async Task <IActionResult> Put([FromBody] SupplierBindingModel model)
        {
            var supplier = await _supplierService.UpdateSupplier(_mapper.Map <Supplier>(model));

            return(Ok(_mapper.Map <SupplierBindingModel>(supplier)));
        }