Exemplo n.º 1
0
        public async Task <ActionResult <OffCodeViewModel> > PostCategory(OffCodeViewModel viewModel)
        {
            var offCode = new Models.OffCodes()
            {
                Id         = viewModel.Id,
                Title      = viewModel.Title,
                CreateDate = DateTime.Now,
                Code       = viewModel.Code,
                Products   = (ICollection <Product>)viewModel.Products,
            };
            await UnitOfWork.OffCodeRepository.Insert(offCode);

            //_context.People.Add(person);
            await UnitOfWork.SaveAsync();

            return(CreatedAtAction("GetOffCode", new { id = viewModel.Id }, viewModel));
        }
Exemplo n.º 2
0
        public async Task <ActionResult <OffCodeViewModel> > GetOffCode(int id)
        {
            var offCode = await UnitOfWork.OffCodeRepository.GetById(id);

            var offCodeView = new OffCodeViewModel
            {
                Code     = offCode.Code,
                Title    = offCode.Title,
                Products = (ICollection <ProductViewModel>)offCode.Products,
                Id       = offCode.Id
            };

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

            return(offCodeView);
        }
Exemplo n.º 3
0
        public async Task <IActionResult> PutOffCode(OffCodeViewModel viewModel)
        {
            var getId = await UnitOfWork.OffCodeRepository.GetById(viewModel.Id);

            var offCodeUpdate = new Models.OffCodes
            {
                Id       = viewModel.Id,
                Code     = viewModel.Code,
                Products = (ICollection <Product>)viewModel.Products,
                Title    = viewModel.Title,
            };

            if (getId.Id != viewModel.Id)
            {
                return(BadRequest());
            }
            await UnitOfWork.OffCodeRepository.Update(offCodeUpdate);

            //_context.Entry(person).State = EntityState.Modified;

            try
            {
                await UnitOfWork.SaveAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!IsExists(getId.Id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Exemplo n.º 4
0
 public Task <OffCodeViewModel> PostAsync(OffCodeViewModel viewModel)
 {
     throw new NotImplementedException();
 }