public async Task <long> Create(AddCategoryVMRequest entity) { var response = await _httpService.Post2 <AddCategoryVMRequest, long>(url, entity); if (!response.Success) { throw new ApplicationException(await response.GetBody()); } return(response.Response); }
public async Task <ActionResult> Post(AddCategoryVMRequest 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(AddCategoryVMRequest entity) { try { long max = 0; var query = await _entityRepository.TableNoTracking.FirstOrDefaultAsync(); if (query != null) { max = await _entityRepository.TableNoTracking.MaxAsync(x => x.Id); } Category category = new() { Name_ar = entity.Name_ar, Name_en = entity.Name_en, Name_fr = entity.Name_fr, Name_tr = entity.Name_tr, Name_ru = entity.Name_ru, Description_ar = entity.Description_ar, Description_en = entity.Description_en, Description_fr = entity.Description_fr, Description_tr = entity.Description_tr, Description_ru = entity.Description_ru, Image = entity.Image, CategoryLevel = entity.CategoryLevel, ParentId = entity.ParentId, Code = $"Category_{max + 1}" }; if (!string.IsNullOrWhiteSpace(entity.Image)) { var entityImage = Convert.FromBase64String(entity.Image); category.Image = await _fileService.SaveFile(entityImage, "jpg", path, category.Code); } var newEntity = await _entityRepository.InsertAsync(category); return(ApiResponse.Create(HttpStatusCode.OK, newEntity.Id)); } catch (Exception) { return(ApiResponse.Create(HttpStatusCode.InternalServerError, null, "InternalServerError_Error")); } }