public async Task <IActionResult> Update(int id, [FromBody] SaveMealOrderResource mealOrderResource) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var mealOrder = await mealOrderRepository.GetOne(id); if (mealOrder == null) { return(NotFound()); } if (mealOrder.UserId != mealOrderResource.UserId) { mealOrderResource.UserId = mealOrder.UserId; } if (mealOrder.IsReadyToCollect == true && mealOrderResource.isReadyToCollect == true) { return(BadRequest("Can't edit the record since it was ready to collect, please disable ready to collect then save and try again")); } if (mealOrder.IsReadyToCollect == false) { mealOrder = mapper.Map(mealOrderResource, mealOrder); } if (mealOrder.IsReadyToCollect == true && mealOrderResource.isReadyToCollect == false) { if (mealOrder.MealOrderVerificationId != null) { var mealVerification = await orderVerificationRepository.GetOne(mealOrder.MealOrderVerificationId.Value); if (mealVerification.IsClosed == true) { return(BadRequest("Can't edit the record since it was close in verification")); } } mealOrder.IsReadyToCollect = false; } if (await unitOfWork.CompleteAsync() == false) { throw new Exception(message: $"Updating order with id: {id} failed on save"); } mealOrder = await mealOrderRepository.GetOne(mealOrder.Id); var result = mapper.Map <MealOrder, ViewMealOrderResource>(mealOrder); return(Ok(result)); }
public async Task <IActionResult> GetOne(int id) { var mealOrderVerification = await mealOrderVerificationRepository.GetOne(id); if (mealOrderVerification == null) { return(NotFound()); } var result = mapper.Map <MealOrderVerification, ViewMealOrderVerificationResource>(mealOrderVerification); return(Ok(result)); }