Пример #1
0
        public ManufacturerViewModel saveManufacturer(ManufacturerViewModel manufacturerViewModel)
        {
            //throw new NotImplementedException();

            ManufacturerDTO manufacturerDTO = new ManufacturerDTO();

            var manufacturerMapper = new ecvMapper <ManufacturerModel, ManufacturerDTO>();

            manufacturerDTO = manufacturerMapper.CreateMappedObject(manufacturerViewModel.manufacturerModel);

            var _manufacturerServiceStatus = _mnfService.SaveEntity(manufacturerDTO);

            if (_manufacturerServiceStatus.operationStatus == OperationStatus.Error)
            {
                manufacturerViewModel.operationStatus = OperationStatus.Error;
                if (!string.IsNullOrEmpty(_manufacturerServiceStatus.OperationMessage))
                {
                    manufacturerViewModel.OperationMessage = _manufacturerServiceStatus.OperationMessage;
                }

                manufacturerViewModel.ecvRuleViolation = _manufacturerServiceStatus.ecvRuleViolation;
            }
            else
            {
                manufacturerViewModel.operationStatus = OperationStatus.Success;
                if (!string.IsNullOrEmpty(_manufacturerServiceStatus.OperationMessage))
                {
                    manufacturerViewModel.OperationMessage = _manufacturerServiceStatus.OperationMessage;
                }
                manufacturerViewModel.ecvRuleViolation = _manufacturerServiceStatus.ecvRuleViolation;
            }

            return(manufacturerViewModel);
        }
Пример #2
0
        public async Task <IActionResult> PutManufacturer([FromRoute] int id, [FromBody] ManufacturerDTO manufacturerDTO)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != manufacturerDTO.Id)
            {
                return(BadRequest());
            }
            var manufacturer = await _context.Manufacturer.FindAsync(id);

            manufacturer.Name = manufacturerDTO.Name;
            _context.Entry(manufacturer).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!ManufacturerExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Пример #3
0
        public async Task ManufacturerService_Should_Update_Manufacturer()
        {
            // Arrange
            SetUpUnitOfWork();
            var service = new ManufacturerService(_unitOfWork.Object, _mapper);
            var entity  = new ManufacturerDTO()
            {
                Name = "TestName",
            };

            var newEntity = new ManufacturerDTO()
            {
                Name = "NewTestName",
            };

            await service.CreateAsync(entity);

            await _unitOfWork.Object.SaveAsync();

            // Act
            entity.Name = newEntity.Name;
            await service.UpdateAsync(entity);

            await _unitOfWork.Object.SaveAsync();

            // Assert
            Assert.NotNull(entity);
            Assert.Equal(newEntity.Name, entity.Name);
        }
        private void InitCommands()
        {
            RemoveGoodCommand = new RelayCommand(x =>
            {
                goodService.Remove(SelectedGood);
                Goods.Remove(SelectedGood);
            });

            RemoveCategoryCommand = new RelayCommand(x =>
            {
                categoryService.Remove(SelectedCategory);
                Categories.Remove(SelectedCategory);
            });

            RemoveManufacturerCommand = new RelayCommand(x =>
            {
                manufacturerService.Remove(SelectedManufactirer);
                Manufacturers.Remove(SelectedManufactirer);
            });

            AddUpdateGoodCommand = new RelayCommand(x =>
            {
                AddUpdateGood dlg = new AddUpdateGood();
                dlg.ShowDialog();
                var good = new GoodDTO
                {
                    GoodName       = GoodViewModelProxy.Proxy.GoodName,
                    GoodCount      = GoodViewModelProxy.Proxy.GoodCount,
                    Price          = GoodViewModelProxy.Proxy.GoodPrice,
                    CategoryId     = categoryService.GetAll().FirstOrDefault(y => y.CategoryName == GoodViewModelProxy.Proxy.GoodCategory).CategoryId,
                    ManufacturerId = manufacturerService.GetAll().FirstOrDefault(y => y.ManufacturerName == GoodViewModelProxy.Proxy.GoodManufacturer).ManufacturerId
                };
                var result = goodService.CreateOrUpdate(good);
                Goods.Add(result);
            });

            AddUpdateCategoryCommand = new RelayCommand(x =>
            {
                AddUpdateCategoryView dlg = new AddUpdateCategoryView();
                dlg.ShowDialog();
                var category = new CategoryDTO
                {
                    CategoryName = CategoryViewModelProxy.Proxy.CategoryName
                };
                var result = categoryService.CreateOrUpdate(category);
                Categories.Add(result);
            });

            AddUpdateManufacturerCommand = new RelayCommand(x =>
            {
                AddUpdateManufactorerView dlg = new AddUpdateManufactorerView();
                dlg.ShowDialog();
                var manufactorer = new ManufacturerDTO
                {
                    ManufacturerName = ManufacturerModelProxy.Proxy.ManufacturerName
                };
                var result = manufacturerService.CreateOrUpdate(manufactorer);
                Manufacturers.Add(result);
            });
        }
Пример #5
0
        public void CreateManufacturer(ManufacturerDTO item)
        {
            var mapper = new MapperConfiguration(cg => cg.CreateMap <ManufacturerDTO, Manufacturer>()).CreateMapper();
            var mr     = mapper.Map <ManufacturerDTO, Manufacturer>(item);

            Db.Manufacturers.Create(mr);
            Db.Save();
        }
Пример #6
0
 public ActionResult ManufacturerEdit(ManufacturerDTO manufacturer)
 {
     if (ModelState.IsValid)
     {
         service.CreateOrUpdate(manufacturer);
         service.SaveAll(); return(RedirectToAction("ManufacturerView"));
     }
     return(RedirectToAction("ManufacturerEdit"));
 }
Пример #7
0
        public async Task <ManufacturerDTO> UpdateAsync(ManufacturerDTO dto)
        {
            var model = _mapper.Map <Manufacturer>(dto);

            _unitOfWork.ManufacturerRepository.Update(model);
            await _unitOfWork.SaveAsync();

            return(_mapper.Map <ManufacturerDTO>(model));
        }
Пример #8
0
 public ActionResult CreateManufacturer(ManufacturerDTO manufacturerViewModel)
 {
     if (ModelState.IsValid)
     {
         manufacturerService.CreateOrUpdate(manufacturerViewModel);
         return(RedirectToAction("Index"));
     }
     return(View(manufacturerViewModel));
 }
Пример #9
0
 public ActionResult Edit(ManufacturerDTO manufacturer)
 {
     if (ModelState.IsValid)
     {
         manufacturerService.AddOrUpdate(manufacturer);
         return(RedirectToAction("IndexHtmlAction"));
     }
     return(View("Edit"));
 }
Пример #10
0
        public Manufacturer Post(ManufacturerDTO value)
        {
            Manufacturer manufacturer = new Manufacturer()
            {
                Name     = value.Name,
                Location = value.Location
            };

            return(IManufacturerRepo.Create(manufacturer));
        }
Пример #11
0
        public async Task <IHttpActionResult> GetById(int id)
        {
            ManufacturerDTO Manufacturer = await ManufacturerService.GetAll().Where(x => x.Id == id && !x.Deleted).ProjectTo <ManufacturerDTO>().FirstOrDefaultAsync();

            if (Manufacturer == null)
            {
                return(NotFound());
            }
            return(Ok(Manufacturer));
        }
        public async Task <IActionResult> UpdateManufacturer(int id)
        {
            var manufacturer = await manufacturerService.GetByIdAsync(id);

            var             config = new MapperConfiguration(cfg => cfg.CreateMap <Manufacturer, ManufacturerDTO>());
            var             mapper = new Mapper(config);
            ManufacturerDTO manDTO = mapper.Map <Manufacturer, ManufacturerDTO>(manufacturer);

            return(View(manDTO));
        }
Пример #13
0
        public async Task <ManufacturerDTO> CreateManufacturer(ManufacturerDTO ManufacturerDTO)
        {
            Manufacturer manufacturer = new Manufacturer {
                CountryId = ManufacturerDTO.CountryId, Name = ManufacturerDTO.Name
            };
            await db.Manufacturers.AddAsync(manufacturer);

            await db.SaveChangesAsync();

            return(ManufacturerDTO);
        }
Пример #14
0
 public void CreateManufacturer(ManufacturerDTO viewmodel)
 {
     try
     {
         var manufacturer = Mapper.Map <ManufacturerDTO, Manufacturer>(viewmodel);
         _manufacturerRepository.AddNewManufacturer(manufacturer);
     }
     catch (Exception ex)
     {
         throw;
     }
 }
Пример #15
0
 public ActionResult <ManufacturerDTO> GetManufacturer(int ManufacturerId)
 {
     try
     {
         ManufacturerDTO manufacturer = serv.GetManufacturer(ManufacturerId);
         return(Ok(manufacturer));
     }
     catch (ValidationException ex)
     {
         return(Content(ex.Message));
     }
 }
Пример #16
0
        public PartialViewResult ManufacturerEdit(int id = 1)
        {
            if (id < 0)
            {
                ManufacturerDTO createDTO = new ManufacturerDTO();
                service.CreateOrUpdate(createDTO);
                return(PartialView(createDTO));
            }
            ManufacturerDTO manufacturer = service.Get(id);

            return(PartialView(manufacturer));
        }
        public async Task <IActionResult> UpdateManufacturer(ManufacturerDTO manuf, string country)
        {
            var config = new MapperConfiguration(cfg => cfg.CreateMap <ManufacturerDTO, Manufacturer>());
            var mapper = new Mapper(config);

            Manufacturer manufacturer = mapper.Map <ManufacturerDTO, Manufacturer>(manuf);

            country = "USA";
            await manufacturerService.UpdateManufacturer(manufacturer.Id, manufacturer.Name, country);

            return(RedirectToAction("Index"));
        }
Пример #18
0
 public ActionResult Delete(int id)
 {
     try
     {
         ManufacturerDTO manufacturer = manufacturerService.Get(id);
         manufacturerService.Delete(manufacturer);
         return(Json("OK"));
     }
     catch
     {
         return(Json("Error"));
     }
 }
Пример #19
0
 public async Task <ActionResult <ManufacturerDTO> > CreateManufacturer(ManufacturerDTO ManufacturerDTO)
 {
     try
     {
         await serv.CreateManufacturer(ManufacturerDTO);
     }
     catch (Exception ex)
     {
         var err = new { error = ex.Message };
         return(Ok(err));
     }
     return(Ok(ManufacturerDTO));
 }
Пример #20
0
        public async Task <IHttpActionResult> Create([FromBody] ManufacturerDTO ManufacturerDto)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var entity = ManufacturerDto.ToEntity();

            entity.CreateUserId = User.Identity.GetUserId();
            entity.CreateTime   = DateTime.Now;
            await ManufacturerService.InsertAsync(entity);

            return(Ok(entity.ToModel()));
        }
Пример #21
0
        public void Put(int id, ManufacturerDTO value)
        {
            Manufacturer manufacturer = IManufacturerRepo.Get(id);

            if (value.Name != null)
            {
                manufacturer.Name = value.Name;
            }
            if (value.Location != null)
            {
                manufacturer.Location = value.Location;
            }

            IManufacturerRepo.Update(manufacturer);
        }
Пример #22
0
        public ActionResult UploadPhoto(HttpPostedFileBase fileUpload)
        {
            string Id = Request.Params["id"];

            if (fileUpload != null)
            {
                ManufacturerDTO manufacturer = manufacturerService.Get(Convert.ToInt32(Id));
                manufacturer.ManufacturerPhotoPath = "/Images/" + fileUpload.FileName;
                manufacturerService.AddOrUpdate(manufacturer);
            }
            string path = Path.Combine(Server.MapPath("~/Images/"), fileUpload.FileName);

            fileUpload.SaveAs(path);
            return(RedirectToAction("Edit", "Manufacturer", new { id = Convert.ToInt32(Id) }));
        }
        public async Task <IActionResult> AddManufacturer(ManufacturerDTO manDTO, string country)
        {
            if (!ModelState.IsValid)
            {
                return(await Task.Run(() => View(manDTO)));
            }
            var config = new MapperConfiguration(cfg => cfg.CreateMap <ManufacturerDTO, Manufacturer>());
            var mapper = new Mapper(config);

            Manufacturer manufacturer = mapper.Map <ManufacturerDTO, Manufacturer>(manDTO);

            country = "USA";
            await manufacturerService.CreateManufacturerAsync(manDTO.Name, country);

            return(RedirectToAction("Index"));
        }
Пример #24
0
        public List <ManufacturerDTO> CreateManufacturerDTOs()
        {
            List <ManufacturerDTO> manufacturerDTOList = new List <ManufacturerDTO>();
            var manufacturers = GetManufacturers();

            foreach (Manufacturer manufacturer in manufacturers)
            {
                ManufacturerDTO manufacturerDTO = new ManufacturerDTO
                {
                    ManufacturerKey  = manufacturer.ManufacturerKey,
                    ManufacturerName = manufacturer.ManufacturerName
                };
                manufacturerDTOList.Add(manufacturerDTO);
            }
            return(manufacturerDTOList);
        }
Пример #25
0
        public async Task <IActionResult> PostManufacturer([FromBody] ManufacturerDTO manufacturerDTO)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var manufacturer = new Manufacturer
            {
                Name = manufacturerDTO.Name
            };

            _context.Manufacturer.Add(manufacturer);
            await _context.SaveChangesAsync();

            return(CreatedAtAction(nameof(GetManufacturer), new { id = manufacturer.Id }, ManufacturerDTO.FromManufacturer(manufacturer)));
        }
Пример #26
0
        public async Task ManufacturerService_Should_Create_Manufacturer_Async()
        {
            // Arrange
            SetUpUnitOfWork();
            var service        = new ManufacturerService(_unitOfWork.Object, _mapper);
            var expectedEntity = new ManufacturerDTO()
            {
                Name = "TestName",
            };

            // Act
            var actualEntity = await service.CreateAsync(expectedEntity);

            await _unitOfWork.Object.SaveAsync();

            // Assert
            Assert.NotNull(actualEntity);
            Assert.Equal(expectedEntity.Name, actualEntity.Name);
        }
Пример #27
0
        public async Task <IActionResult> DeleteManufacturer([FromRoute] int id)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var manufacturer = await _context.Manufacturer.FindAsync(id);

            if (manufacturer == null)
            {
                return(NotFound());
            }

            _context.Manufacturer.Remove(manufacturer);
            await _context.SaveChangesAsync();

            return(Ok(ManufacturerDTO.FromManufacturer(manufacturer)));
        }
Пример #28
0
        public ManufacturerDTO GetManufacturerById(int manufacturerId)
        {
            var _manufacturer = _unitOfWork.manufacturerRepository.Get(manufacturerId);

            ManufacturerDTO _manufacturerDTO;

            if (_manufacturer == null)
            {
                _manufacturerDTO = null;
            }
            else
            {
                _manufacturerDTO = new ManufacturerDTO();
                var manufacturerMapper = new ecvMapper <Manufacturer, ManufacturerDTO>();

                _manufacturerDTO = manufacturerMapper.CreateMappedObject(_manufacturer);
            }

            return(_manufacturerDTO);
        }
Пример #29
0
        public async Task ManufacturerService_Should_Delete_Manufacturer_Async()
        {
            // Arrange
            SetUpUnitOfWork();
            var service = new ManufacturerService(_unitOfWork.Object, _mapper);
            var entity  = new ManufacturerDTO()
            {
                Name = "TestName",
            };

            entity = await service.CreateAsync(entity);

            await _unitOfWork.Object.SaveAsync();

            // Act
            await service.DeleteAsync(entity.Id);

            await _unitOfWork.Object.SaveAsync();

            // Assert
            Assert.Null(await service.GetAsync(entity.Id));
        }
Пример #30
0
 public void Update(ManufacturerDTO item)
 {
     item.TimeStamps = DateTime.Now;
     _unitOfWork.EFRepository <Manufacturer>().Update(_mapper.Map <Manufacturer>(item));
 }
Пример #31
0
 public static ManufacturerDTO CreateManufacturerDTO(global::System.Guid ID, int type)
 {
     ManufacturerDTO manufacturerDTO = new ManufacturerDTO();
     manufacturerDTO.Id = ID;
     manufacturerDTO.Type = type;
     return manufacturerDTO;
 }
Пример #32
0
 public void AddToManufacturers(ManufacturerDTO manufacturerDTO)
 {
     base.AddObject("Manufacturers", manufacturerDTO);
 }