protected static string ValidateAddress(string address) { if (string.IsNullOrEmpty(address)) { throw ShopException.InvalidLocationAddressException(address); } return(address); }
protected static float ValidateLongitude(float longitude) { if (longitude > 180f || longitude < -180f) { throw ShopException.InvalidLocationLongitudineException(longitude); } return(longitude); }
private static string ValidateName(string name) { if (string.IsNullOrEmpty(name)) { throw ShopException.InvalidNameException(name); } return(name); }
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); }
private static string ValidateDescription(string description) { if (string.IsNullOrEmpty(description)) { throw ShopException.InvalidDescriptionException(description); } return(description); }
protected static string ValidatePostalCode(string postalCode) { if (string.IsNullOrEmpty(postalCode)) { throw ShopException.InvalidLocationPostalCodeException(postalCode); } return(postalCode); }
private static string ValidateDiscount(string discount) { if (string.IsNullOrEmpty(discount)) { throw ShopException.InvalidDiscountException(discount); } return(discount); }
protected static string ValidateProvince(string province) { if (string.IsNullOrEmpty(province)) { throw ShopException.InvalidLocationProvinceException(province); } return(province); }
protected static float ValidateLatitude(float latitude) { if (latitude > 90f || latitude < -90f) { throw ShopException.InvalidLocationLatitudeException(latitude); } return(latitude); }
protected static string ValidateCity(string city) { if (string.IsNullOrEmpty(city)) { throw ShopException.InvalidLocationCityException(city); } return(city); }
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(); }
private static string ValidatePhoneNumber(string phoneNumber) { if (phoneNumber == "") { return(phoneNumber); } if (!PhoneNumberValidation.IsValid(phoneNumber)) { throw ShopException.InvalidPhoneNumberException(phoneNumber); } return(phoneNumber); }
private static string ValidateLinkToSite(string linkToSite) { if (linkToSite == "") { return(linkToSite); } if (!UrlValidation.IsValid(linkToSite)) { throw ShopException.InvalidLinkToSiteException(linkToSite); } return(linkToSite); }
private byte[] ValidateCoverPicture(byte[] newCoverPicture) { if (newCoverPicture == null) { return(this.coverPicture); } if (newCoverPicture.Length == 0) { throw ShopException.InvalidCoverPictureException(newCoverPicture); } return(newCoverPicture); }
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); }
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 }); }
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); }