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)); }
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()); }