Example #1
0
        public IActionResult Add()
        {
            DTOInventory model = new DTOInventory();

            model.Cities = _unitOfWork.Cities.GetAll().Select(c => new SelectListItem(c.Name, c.Id.ToString())).ToList();
            return(PartialView("AddEdit", model));
        }
        void IInventoryService.Edit(DTOInventory inventory)
        {
            Address address = _mapper.Map <Address>(inventory.Address);

            _context.Update(address);
            PhoneNumber phone = _mapper.Map <PhoneNumber>(inventory.PhoneNumber);

            _context.Update(phone);
            base.Edit(_mapper.Map <Inventory>(inventory));
        }
Example #3
0
        public IActionResult Edit(int id)
        {
            DTOInventory model = _unitOfWork.Inventories.GetByIdDto(id);

            if (model == null)
            {
                return(RedirectToAction(nameof(Index)));
            }

            model.Cities = _unitOfWork.Cities.GetAll().Select(x => new SelectListItem(x.Name, x.Id.ToString())).ToList();
            return(PartialView("AddEdit", model));
        }
Example #4
0
        public IActionResult Save(DTOInventory model)
        {
            if (model.Id == 0)
            {
                _unitOfWork.Inventories.Add(model);
            }
            else
            {
                _unitOfWork.Inventories.Edit(model);
            }

            return(RedirectToAction(nameof(Index)));
        }
        void IInventoryService.Add(DTOInventory inventory)
        {
            PhoneNumber phone   = inventory.PhoneNumber;
            Address     address = _mapper.Map <Address>(inventory.Address);
            Inventory   i       = _mapper.Map <Inventory>(inventory);

            _context.Add(phone);
            _context.Add(address);
            _context.SaveChanges();

            i.PhoneNumberId = phone.Id;
            i.AddressId     = address.Id;
            _context.Add(i);
            _context.SaveChanges();
        }