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

                if (query != null)
                {
                    max = await _entityRepository.TableNoTracking.MaxAsync(x => x.Id);
                }
                City city = 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,
                    CountryId = entity.CountryId,
                    Code      = $"City_{max + 1}"
                };
                var newEntity = await _entityRepository.InsertAsync(city);

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

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