Exemplo n.º 1
0
        protected static string ValidateAddress(string address)
        {
            if (string.IsNullOrEmpty(address))
            {
                throw ShopException.InvalidLocationAddressException(address);
            }

            return(address);
        }
Exemplo n.º 2
0
        protected static float ValidateLongitude(float longitude)
        {
            if (longitude > 180f || longitude < -180f)
            {
                throw ShopException.InvalidLocationLongitudineException(longitude);
            }

            return(longitude);
        }
Exemplo n.º 3
0
        private static string ValidateName(string name)
        {
            if (string.IsNullOrEmpty(name))
            {
                throw ShopException.InvalidNameException(name);
            }

            return(name);
        }
Exemplo n.º 4
0
        public string handleShopExceptionAsync(HttpContext context, ShopException ex)
        {
            var message = "Huston we got a database problem";

            context.Response.ContentType = "application/json";
            context.Response.StatusCode  = (int)HttpStatusCode.NotAcceptable;
            message = ex.Message;
            return(message);
        }
Exemplo n.º 5
0
        private static string ValidateDescription(string description)
        {
            if (string.IsNullOrEmpty(description))
            {
                throw ShopException.InvalidDescriptionException(description);
            }

            return(description);
        }
Exemplo n.º 6
0
        protected static string ValidatePostalCode(string postalCode)
        {
            if (string.IsNullOrEmpty(postalCode))
            {
                throw ShopException.InvalidLocationPostalCodeException(postalCode);
            }

            return(postalCode);
        }
Exemplo n.º 7
0
        private static string ValidateDiscount(string discount)
        {
            if (string.IsNullOrEmpty(discount))
            {
                throw ShopException.InvalidDiscountException(discount);
            }

            return(discount);
        }
Exemplo n.º 8
0
        protected static string ValidateProvince(string province)
        {
            if (string.IsNullOrEmpty(province))
            {
                throw ShopException.InvalidLocationProvinceException(province);
            }

            return(province);
        }
Exemplo n.º 9
0
        protected static float ValidateLatitude(float latitude)
        {
            if (latitude > 90f || latitude < -90f)
            {
                throw ShopException.InvalidLocationLatitudeException(latitude);
            }

            return(latitude);
        }
Exemplo n.º 10
0
        protected static string ValidateCity(string city)
        {
            if (string.IsNullOrEmpty(city))
            {
                throw ShopException.InvalidLocationCityException(city);
            }

            return(city);
        }
Exemplo n.º 11
0
        public async Task DeleteShopAsync(int id)
        {
            var shop = await this.modelContext.Shops.FindAsync(id);

            if (shop == null)
            {
                throw ShopException.ShopIdNotFoundException(id);
            }

            this.modelContext.Shops.Remove(shop);
            await this.modelContext.SaveChangesAsync();
        }
Exemplo n.º 12
0
        private static string ValidatePhoneNumber(string phoneNumber)
        {
            if (phoneNumber == "")
            {
                return(phoneNumber);
            }

            if (!PhoneNumberValidation.IsValid(phoneNumber))
            {
                throw ShopException.InvalidPhoneNumberException(phoneNumber);
            }

            return(phoneNumber);
        }
Exemplo n.º 13
0
        private static string ValidateLinkToSite(string linkToSite)
        {
            if (linkToSite == "")
            {
                return(linkToSite);
            }

            if (!UrlValidation.IsValid(linkToSite))
            {
                throw ShopException.InvalidLinkToSiteException(linkToSite);
            }

            return(linkToSite);
        }
Exemplo n.º 14
0
        private byte[] ValidateCoverPicture(byte[] newCoverPicture)
        {
            if (newCoverPicture == null)
            {
                return(this.coverPicture);
            }

            if (newCoverPicture.Length == 0)
            {
                throw ShopException.InvalidCoverPictureException(newCoverPicture);
            }

            return(newCoverPicture);
        }
Exemplo n.º 15
0
        public async Task <byte[]> GetCoverPictureAsync(int id)
        {
            var shop = await this.modelContext.Shops
                       .AsNoTracking()
                       .Include(s => s.CoverPicture)
                       .FirstOrDefaultAsync(s => s.Id == id);

            if (shop == null)
            {
                throw ShopException.ShopIdNotFoundException(id);
            }

            return(shop.CoverPicture);
        }
Exemplo n.º 16
0
        public async Task <ShopInfoDto> GetShopAsync(int id)
        {
            var shop = await this.modelContext.Shops
                       .Include(s => s.CoverPicture)
                       .AsNoTracking()
                       .FirstOrDefaultAsync(s => s.Id == id);

            if (shop == null)
            {
                throw ShopException.ShopIdNotFoundException(id);
            }

            return(new ShopInfoDto()
            {
                Id = shop.Id,
                Description = shop.Description,
                Discount = shop.Discount,
                LinkToSite = shop.LinkToSite,
                Location = shop.Location,
                Name = shop.Name,
                PhoneNumber = shop.PhoneNumber
            });
        }
Exemplo n.º 17
0
        public async Task <Shop> ChangeShopDataAsync(int shopId, Shop shop)
        {
            if (shop == null)
            {
                throw new ArgumentNullException("shop cannot be null");
            }

            var updateShop = await this.modelContext.Shops.FindAsync(shopId);

            if (updateShop == null)
            {
                throw ShopException.ShopIdNotFoundException(shopId);
            }

            updateShop.SetName(shop.Name);
            updateShop.SetLinkToSite(shop.LinkToSite);
            updateShop.SetDescription(shop.Description);
            updateShop.SetDiscount(shop.Discount);
            updateShop.SetLocation(shop.Location);
            updateShop.SetPhoneNumber(shop.PhoneNumber);
            updateShop.SetCoverPicture(shop.CoverPicture);

            await using var transaction = await this.modelContext.Database.BeginTransactionAsync();

            await this.modelContext.SaveChangesAsync();

            if (shop.CoverPicture != null)
            {
                var fileId = BuildFileIdFromShopId(shop.Id);
                await this.fileStorageService.StoreFileAsync(fileId, updateShop.CoverPicture);
            }

            await transaction.CommitAsync();

            return(updateShop);
        }