/// <summary> /// Update the lot. /// </summary> /// <param name="id"></param> /// <param name="updatedLot"></param> /// <returns> /// Updated lot object. /// </returns> public async Task <Lot> UpdateLotAsync(int id, Lot updatedLot) { if (updatedLot == null) { throw new ArgumentNullException(nameof(updatedLot)); } var lotToUpdate = await _lotRepository.GetByIdAsync(id); if (lotToUpdate == null) { throw new LotNotFoundException(id); } lotToUpdate.LotName = updatedLot.LotName; lotToUpdate.Description = updatedLot.Description; lotToUpdate.EndTime = updatedLot.EndTime; lotToUpdate.CategoryID = updatedLot.CategoryID; lotToUpdate.MinBid = updatedLot.MinBid; lotToUpdate.StartPrice = updatedLot.StartPrice; lotToUpdate.StartTime = updatedLot.StartTime; await MarkLotAsActive(lotToUpdate); await _unitOfWork.CompleteAsync(); return(lotToUpdate); }
public async Task <IActionResult> Update(int id) { var categories = _categoryRepository.GetAll().Select(c => new SelectListItem { Value = c.CategoryID.ToString(), Text = c.CategoryName }); var lot = await _lotRepository.GetByIdAsync(id); var lotCreateVM = _maper.Map <Lot, LotCreateViewModel>(lot); lotCreateVM.Categories = categories; return(View(lotCreateVM)); }
public async Task <IActionResult> DeleteLot(int id) { var lot = await _lotRepository.GetByIdAsync(id); if (lot == null) { return(NotFound()); } await _lotService.DeleteLotAsync(lot); return(Ok(id)); }