public async Task <ApiResponse> PutRate(OrderRateVMRequest entity, string userName) { try { var userId = (await _userCServices.GetCurrent(userName)).Id; var entityDB = await _entityRepository.Table .Where(x => x.UserCId == userId && x.Id == entity.OrderId) .Include(x => x.Product).SingleOrDefaultAsync(); if (entityDB != null) { entityDB.Rate = entity.Rate; await _entityRepository.UpdateAsync(entityDB); var store = await _storeRepository.GetByIdAsync(entityDB.Product.StoreId); store.AverageRate = await CalculateAverage(store.Id); } return(ApiResponse.Create(HttpStatusCode.OK, null)); } catch (Exception) { return(ApiResponse.Create(HttpStatusCode.InternalServerError, null, "InternalServerError_Error")); } }
public async Task EditRate(OrderRateVMRequest entity) { var response = await _httpService.Put <OrderRateVMRequest>($"{url}/PutRate", entity); if (!response.Success) { throw new ApplicationException(await response.GetBody()); } }
public async Task <ActionResult> PutRate(OrderRateVMRequest entity) { #region Start the watch var watch = new Stopwatch(); watch.Start(); #endregion var result = await _entityServices.PutRate(entity, User.Identity.Name); #region End the watch watch.Stop(); result.Meta.TotalProcessingTime = watch.ElapsedMilliseconds; #endregion return(Ok(result)); }
public async Task <ApiResponse> PutRate(OrderRateVMRequest entity, string userName) { try { var userId = (await _userCServices.GetCurrent(userName)).Id; var ratingDB = await _entityRepository.Table.Where(x => x.UserCId == userId && x.Id == entity.OrderId).SingleOrDefaultAsync(); if (ratingDB != null) { ratingDB.Rate = entity.Rate; await _entityRepository.UpdateAsync(ratingDB); } return(ApiResponse.Create(HttpStatusCode.OK, null)); } catch (Exception) { return(ApiResponse.Create(HttpStatusCode.InternalServerError, null, "InternalServerError_Error")); } }