Exemple #1
0
        public async Task <ApiResponse> Post(AddCountryVMRequest entity)
        {
            try
            {
                long max   = 0;
                var  query = await _entityRepository.TableNoTracking.FirstOrDefaultAsync();

                if (query != null)
                {
                    max = await _entityRepository.TableNoTracking.MaxAsync(x => x.Id);
                }
                Country country = 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,
                    Image   = entity.Image,
                    Code    = $"Country_{max + 1}"
                };
                if (!string.IsNullOrWhiteSpace(entity.Image))
                {
                    var entityImage = Convert.FromBase64String(entity.Image);
                    country.Image = await _fileService.SaveFile(entityImage, "jpg", path, country.Code);
                }
                var newEntity = await _entityRepository.InsertAsync(country);

                return(ApiResponse.Create(HttpStatusCode.OK, newEntity.Id));
            }
            catch (Exception)
            {
                return(ApiResponse.Create(HttpStatusCode.InternalServerError, null, "InternalServerError_Error"));
            }
        }
        public async Task <long> Create(AddCountryVMRequest entity)
        {
            var response = await _httpService.Post2 <AddCountryVMRequest, long>(url, entity);

            if (!response.Success)
            {
                throw new ApplicationException(await response.GetBody());
            }
            return(response.Response);
        }
        public async Task <ActionResult> Post(AddCountryVMRequest 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));
        }