private HttpModelResult AddModel(BaseModel model)
        {
            HttpModelResult result = new HttpModelResult();
            StoreDto        dto    = _mapper.Map <StoreDto>(model);

            try
            {
                dto = (StoreDto)_dataStore.AddorUpdate(dto);
                if (dto != null)
                {
                    StoreModel createdModel = _mapper.Map <StoreModel>(dto);
                    result.Model      = createdModel;
                    result.HttpStatus = HttpStatusCode.Created;
                }
                else
                {
                    result.HttpStatus = HttpStatusCode.InternalServerError;
                }
            }
            catch
            {
                result.HttpStatus = HttpStatusCode.InternalServerError;
            }
            return(result);
        }
Example #2
0
        public async Task AddStore_Post_When_StoreTypeList_Not_Null_Should_Return_View_With_Error()
        {
            //arrange

            StoreViewModel storeViewModel = new StoreViewModel
            {
                Id            = 0,
                Name          = "test",
                Promocode     = "test promocode",
                StoreTypeId   = 0,
                StoreTypeList = new List <SelectListItem>()
            };

            StoreDto storeDto = new StoreDto
            {
                Id          = 0,
                Name        = "test",
                Promocode   = "test promocode",
                StoreTypeId = 0
            };

            OperationDetails operationDetails = new OperationDetails(false);

            mapper.Setup(x => x.Map <StoreViewModel, StoreDto>(storeViewModel)).Returns(storeDto);
            storeService.Setup(x => x.AddStoreAsync(storeDto)).ReturnsAsync(operationDetails);
            storeTypeService.Setup(x => x.GetAllStoreType()).Returns(new List <StoreTypeDto>());

            //act
            var actualResult = await storeAdminController.AddStore(storeViewModel);

            //assert
            Assert.IsNotNull(actualResult);
            Assert.IsFalse(storeAdminController.ModelState.IsValid);
            storeService.Verify(x => x.AddStoreAsync(storeDto), Times.Once);
        }
Example #3
0
        public async Task UpdateStore_When_Get_Update_Should_Return_View()
        {
            //arrange
            StoreViewModel storeViewModel = new StoreViewModel
            {
                Id            = 0,
                Name          = "test",
                Promocode     = "test promocode",
                StoreTypeId   = 0,
                StoreTypeList = null
            };

            StoreDto storeDto = new StoreDto
            {
                Id          = 0,
                Name        = "test",
                Promocode   = "test promocode",
                StoreTypeId = 0
            };

            storeService.Setup(x => x.GetStoreByIdAsync(0)).ReturnsAsync(storeDto);
            mapper.Setup(x => x.Map <StoreDto, StoreViewModel>(storeDto)).Returns(storeViewModel);

            //act
            var actualResult = await storeAdminController.UpdateStore(0) as ViewResult;

            //assert
            Assert.IsNotNull(actualResult);
            Assert.IsTrue(storeAdminController.ModelState.IsValid);
            storeService.Verify(x => x.GetStoreByIdAsync(0), Times.Once);
        }
        public StoreDto getStoreDto(String id)
        {
            store    store    = db.stores.Where(s => s.id == id).FirstOrDefault();
            StoreDto storeDto = new StoreDto(store.id, store.name, store.location, statusRepository.getStatus(store.status_id));

            return(storeDto);
        }
Example #5
0
        public dynamic Poststore([FromBody] StoreRequestDto storeDto)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            try
            {
                storeRepository.addStore(storeDto);
            }
            catch (Exception e)
            {
                if (storeRepository.storeExists(storeDto.id))
                {
                    return(Conflict());
                }
                else
                {
                    throw e;
                }
            }

            StoreDto result = storeRepository.getStoreDto(storeDto.id);

            return(Ok(result));
        }
Example #6
0
 private void UpdateView(StoreDto updatedStoreDto)
 {
     SelectedStore.Name     = updatedStoreDto.Name;
     SelectedStore.SellerId = updatedStoreDto.SellerId;
     SelectedStore.Address  = updatedStoreDto.Address;
     storeDataGridView.Refresh();
 }
Example #7
0
        public SimpleResponse <StoreDto> Create(StoreDto dto)
        {
            var response = new SimpleResponse <StoreDto>();

            try
            {
                var model = SimpleMapper.Map <StoreDto, StoreViewModel>(dto);
                var resp  = iStoreBusiness.Create(model);
                response = new SimpleResponse <StoreDto>()
                {
                    ResponseCode    = resp.ResponseCode,
                    ResponseMessage = resp.ResponseMessage,
                    RCode           = resp.RCode
                };

                response.Data = SimpleMapper.Map <StoreViewModel, StoreDto>(resp.Data);
            }
            catch (Exception ex)
            {
                response.ResponseCode    = BusinessResponseValues.InternalError;
                response.ResponseMessage = "Okuma iþleminde hata oluþtu.";
                SimpleFileLogger.Instance.Error(ex);
            }

            return(response);
        }
Example #8
0
        public async Task DeleteStoreAsync_When_Store_Null_Should_Return_Store_Not_Found()
        {
            //arrange
            var expectedResult = new OperationDetails(false, "Store not found", "Store");

            StoreDto storeDto = new StoreDto
            {
                Id          = 0,
                Name        = "Test store",
                Promocode   = "Test Promocode",
                StoreTypeId = 1
            };

            Store store = new Store
            {
                Id          = 0,
                Name        = "Test store",
                Promocode   = "Test Promocode",
                StoreTypeId = 1
            };

            mapper.Setup(x => x.Map <StoreDto, Store>(storeDto)).Returns(store);

            //act
            var actualResult = await storeService.DeleteStoreAsync(storeDto);

            //assert
            actualResult.Should().BeEquivalentTo(expectedResult);
        }
Example #9
0
        public async Task DeleteStoreAsync_When_Correct_Delete_Should_Return_True()
        {
            //arrange
            var expectedResult = new OperationDetails(true);

            StoreDto storeDto = new StoreDto
            {
                Id          = 0,
                Name        = "Test store",
                Promocode   = "Test Promocode",
                StoreTypeId = 1
            };

            Store store = new Store
            {
                Id          = 0,
                Name        = "Test store",
                Promocode   = "Test Promocode",
                StoreTypeId = 1
            };

            mapper.Setup(x => x.Map <StoreDto, Store>(storeDto)).Returns(store);
            storeRepository.Setup(x => x.GetByIdAsync(0)).ReturnsAsync(store);

            //act
            await storeService.DeleteStoreAsync(storeDto);

            //assert
            storeRepository.Verify(x => x.DeleteAsync(store), Times.Once);
        }
Example #10
0
        public async Task AddStoreAsync_When_Duplication_Name_Store_Should_Return_Store_Already_Exists()
        {
            //arrange
            var expectedResult = new OperationDetails(false, "A Store with this name already exists", "StoreType");

            StoreDto storeDto = new StoreDto
            {
                Id          = 0,
                Name        = "Test store",
                Promocode   = "Test Promocode",
                StoreTypeId = 1
            };

            Store store = new Store
            {
                Id          = 0,
                Name        = "Test store",
                Promocode   = "Test Promocode",
                StoreTypeId = 1
            };

            mapper.Setup(x => x.Map <StoreDto, Store>(storeDto)).Returns(store);
            storeRepository.Setup(x => x.GetByName(store.Name)).Returns(store);

            //act
            var actualResult = await storeService.AddStoreAsync(storeDto);

            //assert
            actualResult.Should().BeEquivalentTo(expectedResult);
        }
Example #11
0
        public async Task AddStoreAsync_When_Correct_Add_Store_Should_Return_True()
        {
            //arrange
            var expectedResult = new OperationDetails(true);

            StoreDto storeDto = new StoreDto
            {
                Id          = 0,
                Name        = "Test store",
                Promocode   = "Test Promocode",
                StoreTypeId = 1
            };

            Store store = new Store
            {
                Id          = 0,
                Name        = "Test store",
                Promocode   = "Test Promocode",
                StoreTypeId = 1
            };

            mapper.Setup(x => x.Map <StoreDto, Store>(storeDto)).Returns(store);

            //act
            var actualResult = await storeService.AddStoreAsync(storeDto);

            //assert
            actualResult.Should().BeEquivalentTo(expectedResult);
        }
Example #12
0
        public IHttpActionResult GetCurrentStore(string fields = "")
        {
            Store store = _storeContext.CurrentStore;

            if (store == null)
            {
                return(Error(HttpStatusCode.NotFound, "store", "store not found"));
            }

            StoreDto storeDto = store.ToDto();

            Currency primaryCurrency = _currencyService.GetCurrencyById(_currencySettings.PrimaryStoreCurrencyId);

            if (!String.IsNullOrEmpty(primaryCurrency.DisplayLocale))
            {
                storeDto.PrimaryCurrencyDisplayLocale = primaryCurrency.DisplayLocale;
            }

            var storesRootObject = new StoresRootObject();

            storesRootObject.Stores.Add(storeDto);

            var json = _jsonFieldsSerializer.Serialize(storesRootObject, fields);

            return(new RawJsonActionResult(json));
        }
Example #13
0
        public async Task <ActionResult <StoreDto> > UpdateStore(
            Guid storeId,
            [FromBody] UpdateStoreRequestModel requestModel)
        {
            StoreDto responseModel = await storeService.UpdateStore(
                storeId,
                new UpdateStoreDto()
            {
                Name        = requestModel.Name,
                Description = requestModel.Description,
                BrandId     = requestModel.BrandId,
                Address     = requestModel.Address,
                IsDisabled  = requestModel.IsDisabled,
                Location    = new GeoEntry {
                    Longitude = requestModel.Longitude, Latitude = requestModel.Latitude
                }
            });

            if (responseModel == null)
            {
                return(InvalidRequest());
            }

            return(Ok(responseModel));
        }
Example #14
0
        public StoreDto GetStoreById(int id)
        {
            StoreDto dto     = null;
            var      context = new orderstatusEntities();

            try
            {
                stores_data storeContext = context.stores_data.Where(x => x.id == id).SingleOrDefault();
                if (storeContext != null)
                {
                    dto          = new StoreDto();
                    dto.Id       = storeContext.id;
                    dto.Url      = storeContext.url;
                    dto.Name     = storeContext.name;
                    dto.ApiKey   = storeContext.api_key;
                    dto.Interval = int.Parse(storeContext.interval.ToString());

                    dto.CustomShipmentsDtos = GetCustomShipmentByStoreId(storeContext.id);
                }
                return(dto);
            }
            catch (Exception ex)
            {
                log.Error("Error Exception GetStoreById: " + ex.Message);
                throw;
            }
            finally
            {
                context.Dispose();
            }
        }
Example #15
0
        public async Task <OperationDetails> UpdateStoreAsync(StoreDto storeDto)
        {
            if (storeDto == null)
            {
                Logger.Error("Something went wrong");
                return(new OperationDetails(false, "Something went wrong", "Store"));
            }

            Store store = mapper.Map <StoreDto, Store>(storeDto);

            try
            {
                await unitOfWork.StoreRepository.UpdateAsync(store);

                await unitOfWork.SaveAsync();

                Logger.Info("Successfully updated");
                return(new OperationDetails(true));
            }
            catch (Exception ex)
            {
                Logger.Error(ex.Message);
                return(new OperationDetails(false, ex.Message));
            }
        }
Example #16
0
        public async Task UpdateStoreAsync_When_Correct_Update_Should_Return_True()
        {
            //arrange
            StoreDto storeDto = new StoreDto
            {
                Id          = 0,
                Name        = "Test store",
                Promocode   = "Test Promocode",
                StoreTypeId = 1
            };

            Store store = new Store
            {
                Id          = 0,
                Name        = "Test store",
                Promocode   = "Test Promocode",
                StoreTypeId = 1
            };

            mapper.Setup(x => x.Map <StoreDto, Store>(storeDto)).Returns(store);

            //act
            await storeService.UpdateStoreAsync(storeDto);

            //assert
            storeRepository.Verify(x => x.UpdateAsync(store), Times.Once);
        }
Example #17
0
        private void updateButton_Click(object sender, EventArgs e)
        {
            if (SelectedStore == null)
            {
                return;
            }

            if (StoreName.Length == 0)
            {
                MessageBox.Show(String.Format(Messages.ElEMENT_NAME_REQUIRED, EntityNames.STORE_ENTITY_NAME), Constants.MESSAGE_CAPTION);
                return;
            }

            if (SelectedStore.Name != StoreName &&
                ShoesDataClientServices.StoreServices.ExistStoreByName(StoreName))
            {
                MessageBox.Show(Messages.ELEMENT_EXISTS, Constants.MESSAGE_CAPTION);
                return;
            }

            var updatedStoreDto = new StoreDto
            {
                StoreId  = SelectedStore.StoreId,
                Name     = StoreName,
                Address  = StoreAddress,
                SellerId = SelectedSeller.SellerId
            };

            ShoesDataClientServices.StoreServices.UpdateStore(updatedStoreDto);
            UpdateView(updatedStoreDto);
            MessageBox.Show(String.Format(Messages.ELEMENT_UPDATED_SUCCESS, EntityNames.STORE_ENTITY_NAME), Constants.MESSAGE_CAPTION);
        }
Example #18
0
        private static List <StoreDto> CreateListStoreDto()
        {
            StoreDto storeDto1 = new StoreDto
            {
                Id          = 0,
                Name        = "Test store",
                Promocode   = "Test Promocode",
                StoreTypeId = 1
            };

            StoreDto storeDto2 = new StoreDto
            {
                Id          = 0,
                Name        = "Test store",
                Promocode   = "Test Promocode",
                StoreTypeId = 1
            };

            StoreDto storeDto3 = new StoreDto
            {
                Id          = 0,
                Name        = "Test store",
                Promocode   = "Test Promocode",
                StoreTypeId = 1
            };

            return(new List <StoreDto> {
                storeDto1, storeDto2, storeDto3
            });
        }
Example #19
0
        public IActionResult UpdateInfo([FromBody] StoreDto storeDto)
        {
            try
            {
                var store = _mapper.Map <Store>(storeDto);
                if (store == null)
                {
                    throw new AppException("Неверные данные!");
                }
                var userId = Convert.ToInt32(User.Claims.SingleOrDefault(c => c.Type == ClaimTypes.NameIdentifier)?.Value);

                _logger.LogInformation($"User #{userId}, Update store info #{store.Id}");

                _storeService.UpdateInfo(userId, store);

                return(Ok(new
                {
                }));
            }
            catch (AppException ex)
            {
                return(BadRequest(ex.Message));
            }
            catch (Exception ex)
            {
                _logger.LogCritical($"{ex}");
                return(BadRequest("Service error!"));
            }
        }
Example #20
0
        public async Task UpdateStoreAsync_When_Update_Store_Should_Return_Exception()
        {
            //arrange
            var expectedResult = new OperationDetails(false, "Exception message");

            StoreDto storeDto = new StoreDto
            {
                Id          = 0,
                Name        = "Test store",
                Promocode   = "Test Promocode",
                StoreTypeId = 1
            };

            Store store = new Store
            {
                Id          = 0,
                Name        = "Test store",
                Promocode   = "Test Promocode",
                StoreTypeId = 1
            };

            mapper.Setup(x => x.Map <StoreDto, Store>(storeDto)).Returns(store);
            storeRepository.Setup(x => x.UpdateAsync(store)).Throws(new Exception("Exception message"));

            //act
            var actualResult = await storeService.UpdateStoreAsync(storeDto);

            //assert
            actualResult.Should().BeEquivalentTo(expectedResult);
        }
        public ActionResult <IEnumerable <string> > EditStore([FromBody] StoreDto form, Guid ItemId)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }


            var storeitem = _context.Stored.Where(x => x.Id == ItemId).FirstOrDefault();



            storeitem.Item_Name         = form.Item_Name;
            storeitem.Item_Part         = form.Item_Part;
            storeitem.Item_SerialNumber = form.Item_SerialNumber;
            storeitem.Item_Model        = form.Item_Model;
            storeitem.Item_IsUsed       = form.Item_IsUsed;
            storeitem.Item_Count        = form.Item_Count;



            _context.Entry(storeitem).State = Microsoft.EntityFrameworkCore.EntityState.Modified;
            _context.SaveChanges();

            return(Ok(new Response
            {
                Message = "Done !",
                Data = storeitem,
                Error = false
            }));
        }
Example #22
0
        public async Task GetStoreByIdAsync_When_Correct_Should_return_StoreDto()
        {
            //arrange
            StoreDto storeDto = new StoreDto
            {
                Id          = 0,
                Name        = "Test store",
                Promocode   = "Test Promocode",
                StoreTypeId = 1
            };

            Store store = new Store
            {
                Id          = 0,
                Name        = "Test store",
                Promocode   = "Test Promocode",
                StoreTypeId = 1
            };

            storeRepository.Setup(x => x.GetByIdAsync(0)).ReturnsAsync(store);
            mapper.Setup(x => x.Map <Store, StoreDto>(store)).Returns(storeDto);

            //act
            var actualResult = await storeService.GetStoreByIdAsync(storeDto.Id);

            //assert
            actualResult.Should().BeEquivalentTo(storeDto);
            storeRepository.Verify(x => x.GetByIdAsync(storeDto.Id), Times.Once);
        }
Example #23
0
        public dynamic Putstore(string id, [FromBody] StoreRequestDto storeDto)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != storeDto.id)
            {
                return(BadRequest());
            }
            try
            {
                storeRepository.updateStore(storeDto);
            }
            catch (Exception e)
            {
                if (!storeRepository.storeExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw e;
                }
            }
            StoreDto result = storeRepository.getStoreDto(id);

            return(Ok(result));
        }
Example #24
0
        public async Task UpsertStore(StoreDto input)
        {
            try
            {
                var obj = input.MapTo <Store>();
                if (input.Id == 0)
                {
                    obj.IsDeleted    = false;
                    obj.CreatedBy    = AbpSession.UserId;
                    obj.DateCreated  = DateTime.Now;
                    obj.DateModified = null;
                }
                else
                {
                    obj.ModifiedBy   = AbpSession.UserId;
                    obj.DateModified = DateTime.Now;
                }

                await _storeRepository.InsertOrUpdateAsync(obj);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Example #25
0
        public IHttpActionResult Put(int id, [FromBody] StoreDto dto, [UserProfile] UserProfile userProfile)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }

            var result = CheckRole4Store(userProfile, id);

            if (!result.Result)
            {
                return(BadRequest(result.Error));
            }

            var item = _service.GetItem(id);

            if (item == null)
            {
                return(NotFound());
            }

            dto.Id = id;

            _service.Update(dto, userProfile.Id);

            return(Get(id, userProfile));
        }
Example #26
0
        public async Task <OperationDetails> AddStoreAsync(StoreDto storeDto)
        {
            if (storeDto == null)
            {
                Logger.Error("Something went wrong");
                return(new OperationDetails(false, "Something went wrong", "Store"));
            }

            Store store = mapper.Map <StoreDto, Store>(storeDto);

            try
            {
                //if (unitOfWork.StoreRepository.GetByName(store.Name) != null)
                //{
                //    Logger.Error("A Store with this name already exists");
                //    return new OperationDetails(false, "A Store with this name already exists", "Store");
                //}
                await unitOfWork.StoreRepository.CreateAsync(store);

                await unitOfWork.SaveAsync();

                Logger.Info("Successfully added");
                return(new OperationDetails(true));
            }
            catch (Exception ex)
            {
                Logger.Error(ex.Message);
                return(new OperationDetails(false, "Unfortunately, something went wrong....", "Store"));
            }
        }
Example #27
0
        public async Task AddStore_Post_When_OperationDetails_Is_Succedeed_Should_Return_View_SuccessAdd()
        {
            //arrange
            StoreViewModel storeViewModel = new StoreViewModel
            {
                Id            = 0,
                Name          = "test",
                Promocode     = "test promocode",
                StoreTypeId   = 0,
                StoreTypeList = null
            };

            StoreDto storeDto = new StoreDto
            {
                Id          = 0,
                Name        = "test",
                Promocode   = "test promocode",
                StoreTypeId = 0
            };

            OperationDetails operationDetails = new OperationDetails(true);

            mapper.Setup(x => x.Map <StoreViewModel, StoreDto>(storeViewModel)).Returns(storeDto);
            storeService.Setup(x => x.AddStoreAsync(storeDto)).ReturnsAsync(operationDetails);
            storeTypeService.Setup(x => x.GetAllStoreType()).Returns(new List <StoreTypeDto>());

            //act
            var actualResult = await storeAdminController.AddStore(storeViewModel) as ViewResult;

            //assert
            Assert.IsNotNull(actualResult);
            Assert.IsTrue(storeAdminController.ModelState.IsValid);
            Assert.AreEqual(actualResult.ViewName, "SuccessAdd");
            storeService.Verify(x => x.AddStoreAsync(storeDto), Times.Once);
        }
Example #28
0
        public async Task <OperationDetails> DeleteStoreAsync(StoreDto storeDto)
        {
            if (storeDto == null)
            {
                Logger.Error("Something went wrong");
                return(new OperationDetails(false, "Something went wrong", "Store"));
            }

            Store store = await unitOfWork.StoreRepository.GetByIdAsync(storeDto.Id);

            if (store == null)
            {
                Logger.Error("Store not found");
                return(new OperationDetails(false, "Store not found", "Store"));
            }

            try
            {
                await unitOfWork.StoreRepository.DeleteAsync(store);

                await unitOfWork.SaveAsync();

                Logger.Info("Successfully deleted");
                return(new OperationDetails(true));
            }
            catch (Exception ex)
            {
                Logger.Error(ex.Message);
                return(new OperationDetails(false, ex.Message));
            }
        }
Example #29
0
        public async Task UpdateStorePost_When_OperationDetails_Is_Succedeed_Should_RedirectToAction_StoreTypeList()
        {
            //arrange
            StoreViewModel storeViewModel = new StoreViewModel
            {
                Id            = 0,
                Name          = "test",
                Promocode     = "test promocode",
                StoreTypeId   = 0,
                StoreTypeList = null
            };

            StoreDto storeDto = new StoreDto
            {
                Id          = 0,
                Name        = "test",
                Promocode   = "test promocode",
                StoreTypeId = 0
            };

            OperationDetails operationDetails = new OperationDetails(true);

            mapper.Setup(x => x.Map <StoreViewModel, StoreDto>(storeViewModel)).Returns(storeDto);
            storeService.Setup(x => x.UpdateStoreAsync(storeDto)).ReturnsAsync(operationDetails);

            //act
            var actualResult = await storeAdminController.UpdateStore(storeViewModel) as RedirectToRouteResult;

            //assert
            Assert.IsNotNull(actualResult);
            Assert.IsTrue(storeAdminController.ModelState.IsValid);
            Assert.That(actualResult.RouteValues["action"], Is.EqualTo("StoreTypeList"));
            Assert.That(actualResult.RouteValues["Controller"], Is.EqualTo("StoreTypeAdmin"));
            storeService.Verify(x => x.UpdateStoreAsync(storeDto), Times.Once);
        }
        public IHttpActionResult Poststore(StoreDto storeDto)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            store store = new store();

            store.id        = storeDto.id;
            store.name      = storeDto.name;
            store.location  = storeDto.location;
            store.status_id = storeDto.status.id;
            db.stores.Add(store);

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateException)
            {
                if (storeExists(store.id))
                {
                    return(Conflict());
                }
                else
                {
                    throw;
                }
            }

            return(CreatedAtRoute("DefaultApi", new { id = store.id }, store));
        }