public async Task <long> Create(AddProductVMRequest entity) { var response = await _httpService.Post2 <AddProductVMRequest, long>(url, entity); if (!response.Success) { throw new ApplicationException(await response.GetBody()); } return(response.Response); }
public async Task <ActionResult> Post(AddProductVMRequest entity) { #region Start the watch var watch = new Stopwatch(); watch.Start(); #endregion var result = await _entityServices.Post(entity); #region End the watch watch.Stop(); result.Meta.TotalProcessingTime = watch.ElapsedMilliseconds; #endregion return(Ok(result)); }
public async Task <ApiResponse> Post(AddProductVMRequest entity) { try { long max = 0; var query = await _entityRepository.TableNoTracking.FirstOrDefaultAsync(); if (query != null) { max = await _entityRepository.TableNoTracking.MaxAsync(x => x.Id); } var code = $"Product_{max + 1}"; Product product = new() { Code = code, Image = await HelpImages(entity.Images, code), Colors = HelpColors(entity.Colors), CodeStore = entity.CodeStore, Brand = entity.Brand, Name = entity.Name, Description = entity.Description, MeasruingUnitId = entity.MeasruingUnitId, MinValue = entity.MinValue, Price = entity.Price, Quantity1 = entity.Quantity1, Price1 = entity.Price1, Quantity2 = entity.Quantity2, Price2 = entity.Price2, Quantity3 = entity.Quantity3, Price3 = entity.Price3, CategoryId = entity.CategoryId, Note = entity.Note, StoreId = entity.StoreId, CurrencyId = entity.CurrencyId }; var newEntity = await _entityRepository.InsertAsync(product); return(ApiResponse.Create(HttpStatusCode.OK, newEntity.Id)); } catch (Exception ex) { return(ApiResponse.Create(HttpStatusCode.InternalServerError, null, "InternalServerError_Error")); } }