Пример #1
0
        public List <StoreViewModel> GetSearchedStores(StoreInputModel model)
        {
            if (string.IsNullOrEmpty(model.SearchFied))
            {
                throw _exception.ThrowException(System.Net.HttpStatusCode.BadRequest, "", "Ogiltig förfrågan.");
            }
            var    searchedFields = model.SearchFied.Replace(",", " ");
            var    searchedStores = _storeRepository.GetSearchedStores(searchedFields);
            var    storeList      = new List <StoreViewModel>();
            Random random         = new Random();

            storeList = searchedStores.ConvertAll(x => new StoreViewModel()
            {
                Id             = x.Id,
                Name           = x.Name,
                Email          = x.Email,
                Phone          = x.Phone,
                Address        = x.Address,
                City           = x.City,
                PostalCode     = x.PostalCode,
                QRCode         = x.QRCode,
                Latitude       = x.Latitude,
                Longitude      = x.Longitude,
                Rating         = x.Rating,
                StoreNumber    = x.StoreNumber,
                SupervisorName = x.SupervisorName,
                TotalRatings   = x.TotalRatings
            });
            return(storeList);
        }
Пример #2
0
        public async Task <IActionResult> RegisterStoreAsync([FromBody] StoreInputModel storeInput)
        {
            if (string.IsNullOrWhiteSpace(storeInput.StoreName) || string.IsNullOrWhiteSpace(storeInput.Country) ||
                string.IsNullOrWhiteSpace(storeInput.City))
            {
                var errorMessage = "Invalid input.";
                _logger.LogError(errorMessage);
                return(BadRequest(errorMessage));
            }

            var exists = await _storesRepository.StoreExistsAsync(storeInput.StoreName);

            if (exists)
            {
                var errorMessage = $"Store with name '{storeInput.StoreName}' already registered. Register with a different store name.";
                _logger.LogInformation(errorMessage);
                return(BadRequest(errorMessage));
            }

            var storeDal = storeInput.ToDalEntity();
            await _storesRepository.RegisterStoreAsync(storeDal);

            _logger.LogInformation($"Store with name '{storeInput.StoreName}' registered successfully.");
            return(Ok($"Store '{storeInput.StoreName}' registered Successfully."));
        }
Пример #3
0
        public List <StoreViewModel> GetNearByStores(StoreInputModel model)
        {
            var storeList = new List <StoreViewModel>();

            if (string.IsNullOrEmpty(model.Latitude) && string.IsNullOrEmpty(model.Longitude))
            {
                throw _exception.ThrowException(System.Net.HttpStatusCode.BadRequest, "", "Ogiltig förfrågan.");
            }

            if (string.IsNullOrEmpty(model.Latitude) || string.IsNullOrEmpty(model.Longitude))
            {
                throw _exception.ThrowException(System.Net.HttpStatusCode.BadRequest, "", "Ogiltig förfrågan.");
            }

            var nearByStores = _storeRepository.GetNearByStores(model.Latitude, model.Longitude);

            storeList.AddRange(nearByStores.Select(x => new StoreViewModel()
            {
                Id           = x.Id,
                Name         = x.Name,
                Email        = x.Email,
                Phone        = x.Phone,
                Address      = x.Address,
                City         = x.City,
                PostalCode   = x.PostalCode,
                Latitude     = x.Latitude,
                Longitude    = x.Longitude,
                Rating       = x.Rating,
                StoreNumber  = x.StoreNumber,
                Distance     = x.Distance,
                TotalRatings = x.TotalRatings
            }));
            return(storeList);
        }
Пример #4
0
        public void Create(StoreInputModel store, string UserId)
        {
            var Store = new Store
            {
                Name   = store.Name,
                UserId = UserId
            };

            this.db.Stores.Add(Store);
            this.db.SaveChanges();
        }
Пример #5
0
 public static Dal.Entities.Store ToDalEntity(this StoreInputModel input)
 {
     return(new Dal.Entities.Store
     {
         StoreName = input.StoreName,
         City = input.City,
         Country = input.Country,
         JoinedOn = DateTime.Now,
         Pin = input.Pin
     });
 }
Пример #6
0
        public IActionResult CreateStore(StoreInputModel model)
        {
            if (!this.ModelState.IsValid)
            {
                return(this.Redirect("/Store/CreateStore"));
            }

            var UserId = this.userManager.GetUserId(this.User);

            this.service.Create(model, UserId);

            return(this.Redirect("/"));
        }
Пример #7
0
 public IHttpActionResult SearchStores(StoreInputModel model)
 {
     try
     {
         var searchedStores = _storeService.GetSearchedStores(model);
         return(Ok(new { data = searchedStores }));
     }
     catch (Exception ex)
     {
         _log.ErrorFormat("Error in searching stores by field. Error : {0}", ex.Message);
         _log.Error(ex);
         throw;
     }
 }
Пример #8
0
 public IHttpActionResult GetNearByStores(StoreInputModel model)
 {
     try
     {
         if (model == null)
         {
             throw _exception.ThrowException(HttpStatusCode.BadRequest, "", "Ogiltig förfrågan.");
         }
         var nearByStores = _storeService.GetNearByStores(model);
         return(Ok(new { data = nearByStores }));
     }
     catch (Exception ex)
     {
         _log.ErrorFormat("Error in getting near by stores. Error : {0}", ex.Message);
         _log.Error(ex);
         throw;
     }
 }
Пример #9
0
        public async Task <IActionResult> UpdateStoreAsync([FromRoute] string storeName, [FromBody] StoreInputModel store)
        {
            if (string.IsNullOrWhiteSpace(store.StoreName) || string.IsNullOrWhiteSpace(store.Country) ||
                string.IsNullOrWhiteSpace(store.City))
            {
                var errorMessage = "Invalid input.";
                _logger.LogError(errorMessage);
                return(BadRequest(errorMessage));
            }

            if (storeName.ToLower() != store.StoreName.ToLower())
            {
                return(BadRequest("Failed to update store details. Store name does not match with the name in the updated details."));
            }

            var storeDetails = await _storesRepository.GetStoreAsync(store.StoreName);

            if (storeDetails == null)
            {
                var errorMessage = $"Store with name '{storeName}' doesn't exist.";
                _logger.LogError(errorMessage);
                return(BadRequest(errorMessage));
            }

            var storeDal = store.ToDalEntity();

            storeDal.Id = storeDetails.Id;
            await _storesRepository.UpdateStoreAsync(storeDal);

            _logger.LogInformation($"Details of store with name '{store.StoreName}' updated successfully.");
            return(NoContent());
        }