public async Task <long> Create(AddMessageVMRequest entity) { var response = await _httpService.Post2 <AddMessageVMRequest, long>(url, entity); if (!response.Success) { throw new ApplicationException(await response.GetBody()); } return(response.Response); }
public async Task <ActionResult> Post(AddMessageVMRequest entity) { #region Start the watch var watch = new Stopwatch(); watch.Start(); #endregion var result = await _entityServices.Post(entity, User.Identity.Name); #region End the watch watch.Stop(); result.Meta.TotalProcessingTime = watch.ElapsedMilliseconds; #endregion return(Ok(result)); }
public async Task <ApiResponse> Post(AddMessageVMRequest entity, string userName) { try { long userId = (await _userCServices.GetCurrent(userName)).Id; Order order = await _orderRepository.GetByIdAsync(entity.OrderId); MessageType messageType; if (order.UserCId == userId) { messageType = MessageType.FromCustomer; } else { messageType = MessageType.FromStore; } Message message = new() { OrderId = entity.OrderId, SenderId = userId, Text = entity.Text, MessageType = messageType, MessageDateTime = DateTime.UtcNow }; var newEntity = await _entityRepository.InsertAsync(message); return(ApiResponse.Create(HttpStatusCode.OK, newEntity.Id)); } catch (Exception) { return(ApiResponse.Create(HttpStatusCode.InternalServerError, null, "InternalServerError_Error")); } }