コード例 #1
0
 public IActionResult OnPost()
 {
     if (ModelState.IsValid)
     {
         Shop.Reviews    = new List <Review>();
         Shop.PhotoPaths = new List <Photo>();
         if (Photo.Count > 0)
         {
             Shop.PhotoPaths = FileService.GetPhotoPaths(Photo, webHostEnvironment.WebRootPath);
         }
         Shop.Coordinate = LocationService.GetCoordinates(Shop.ShopAddress);
         shopRepository.AddShop(Shop);
         return(RedirectToPage("./Search/Index"));
     }
     else
     {
         return(Page());
     }
 }
コード例 #2
0
        public async Task <IActionResult> AddShop(ShopCreationDto shop)
        {
            if (!ModelState.IsValid)
            {
                return(UnprocessableEntity());
            }
            var userId = User.FindFirstValue(ClaimTypes.NameIdentifier);

            if (!await _shopRepository.ShopExistByUserID(userId))
            {
                var shopCreation = _mapper.Map <Shop>(shop);
                var location     = _mapper.Map <Location>(shop);
                shopCreation.Location = location;
                shopCreation.UserId   = userId;
                if (await _shopRepository.AddShop(shopCreation))
                {
                    var shopReturn = _mapper.Map <ShopReturnDto>(shopCreation);
                    return(CreatedAtRoute("GetShop", new { id = shopCreation.ShopID }, shopReturn));
                }
                return(BadRequest());
            }
            return(BadRequest("You Already Own a shop, You can't create More than one shop"));
        }
コード例 #3
0
        public async Task <ShopApi> AddShop(ShopApi shop)
        {
            try
            {
                if (shop is null)
                {
                    throw new ArgumentNullException(nameof(shop));
                }

                var shopModel = _mapper.Map <ShopModel>(shop);
                shopModel = await _shopRepository.AddShop(shopModel);

                var outputShopModel = _mapper.Map <ShopApi>(shopModel);
                _logger.LogInformation($"The shop {shop} had been added");

                return(outputShopModel);
            }
            catch (Exception ex)
            {
                _logger.LogError(ex, $"Error while adding the shop {shop}");

                return(null);
            }
        }
コード例 #4
0
 public bool AddShop(Shop shop)
 {
     return(_shopRepository.AddShop(shop));
 }