Example #1
0
        public async Task Edit(EditStoreVMRequest entity)
        {
            var response = await _httpService.Put <EditStoreVMRequest>(url, entity);

            if (!response.Success)
            {
                throw new ApplicationException(await response.GetBody());
            }
        }
Example #2
0
        public async Task <ActionResult> Put(EditStoreVMRequest entity)
        {
            #region Start the watch
            var watch = new Stopwatch();
            watch.Start();
            #endregion

            var result = await _entityServices.Put(entity);

            #region End the watch
            watch.Stop();
            result.Meta.TotalProcessingTime = watch.ElapsedMilliseconds;
            #endregion

            return(Ok(result));
        }
        public async Task <ApiResponse> Put(EditStoreVMRequest entity)
        {
            try
            {
                var entityDB = await _entityRepository.GetByIdAsync(entity.Id);

                if (!string.IsNullOrWhiteSpace(entity.Image))
                {
                    if (entityDB.Image != null)
                    {
                        await _fileService.DeleteFile(entityDB.Image, path);
                    }

                    var entityImage = Convert.FromBase64String(entity.Image);
                    entityDB.Image = await _fileService.EditFile(entityImage, "jpg", path, entityDB.Image, entityDB.Code);
                }
                entityDB.Name       = entity.Name;
                entityDB.Address    = entity.Address;
                entityDB.CityId     = entity.CityId;
                entityDB.CurrencyId = entity.CurrencyId;
                entityDB.Status     = entity.Status;

                //for tabeles linked to this table we delete then Add again
                await _context.Database.ExecuteSqlInterpolatedAsync(
                    $"delete from StoreTags where StoreId = {entity.Id}; delete from StoreCountries where StoreId = {entity.Id}; delete from StoreCities where StoreId = {entity.Id}; delete from StorePaymentMethods where StoreId = {entity.Id};");

                foreach (var item in entity.Tags)
                {
                    StoreTags x = new()
                    {
                        StoreId = entity.Id,
                        TagId   = item
                    };
                    await _context.StoreTags.AddAsync(x);
                }
                foreach (var item in entity.Countries)
                {
                    StoreCountries x = new()
                    {
                        StoreId   = entity.Id,
                        CountryId = item
                    };
                    await _context.StoreCountries.AddAsync(x);
                }
                foreach (var item in entity.Cities)
                {
                    StoreCities x = new()
                    {
                        StoreId = entity.Id,
                        CityId  = item
                    };
                    await _context.StoreCities.AddAsync(x);
                }
                foreach (var item in entity.PaymentMethods)
                {
                    StorePaymentMethods x = new()
                    {
                        StoreId         = entity.Id,
                        PaymentMethodId = item.PaymentMethodId,
                        Details         = item.Details
                    };
                    await _context.StorePaymentMethods.AddAsync(x);
                }

                await _context.SaveChangesAsync();

                await _entityRepository.UpdateAsync(entityDB);

                return(ApiResponse.Create(HttpStatusCode.OK, null));
            }
            catch (Exception)
            {
                return(ApiResponse.Create(HttpStatusCode.InternalServerError, null, "InternalServerError_Error"));
            }
        }