示例#1
0
        public ActionResult New(PlatformTypeViewModel platformTypeViewModel)
        {
            if (ModelState.IsValid)
            {
                var platformTypeDTO = _mapper.Map <ExtendPlatformTypeDTO>(platformTypeViewModel);

                if (!_platformTypeService.IsUniqueEnName(platformTypeDTO))
                {
                    ModelState.AddModelError("NameEn", GlobalRes.ExistPlatformTypeName);
                }

                if (platformTypeViewModel.NameRu != null)
                {
                    if (!_platformTypeService.IsUniqueRuName(platformTypeDTO))
                    {
                        ModelState.AddModelError("NameRu", GlobalRes.ExistPlatformTypeName);
                    }
                }

                if (ModelState.IsValid)
                {
                    _platformTypeService.AddNew(platformTypeDTO);

                    return(RedirectToAction("GetAll"));
                }
            }

            return(View(platformTypeViewModel));
        }
        public void ShouldMap_PlatformTypeDto_To_PlatformTypeViewModel()
        {
            var platformType = new PlatformTypeDto(1, "type");

            PlatformTypeViewModel result = platformType.ToViewModel();

            Assert.AreEqual(platformType.Id, result.Id);
            Assert.AreEqual(platformType.Type, result.Type);
        }
示例#3
0
 private void InitializeTestData(out PlatformTypeViewModel platformTypeViewModel)
 {
     platformTypeViewModel = new PlatformTypeViewModel
     {
         Name    = "name",
         NameRu  = "name ru",
         OldName = "old name"
     };
 }
        public void Update_InvalidUpdatePlatformType_ReturnViewResult()
        {
            var fakePlatformTypeViewModel = new PlatformTypeViewModel();

            _sut.ModelState.Add("testError", new ModelState());
            _sut.ModelState.AddModelError("testError", "test");

            var res = _sut.Update(fakePlatformTypeViewModel);

            Assert.IsType <ViewResult>(res);
        }
示例#5
0
        public ActionResult New(PlatformTypeViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            _platformTypeService.Create(model.Type);

            return(RedirectToAction("GetAll"));
        }
        public void New_InvalidPlatformTypeViewModel_ReturnViewResult()
        {
            var fakePlatformTypeViewModel = new PlatformTypeViewModel()
            {
                NameEn = "test"
            };

            _sut.ModelState.Add("testError", new ModelState());
            _sut.ModelState.AddModelError("testError", "test");

            var res = _sut.New(fakePlatformTypeViewModel);

            Assert.IsType <ViewResult>(res);
        }
示例#7
0
        public IActionResult Update([FromForm] PlatformTypeViewModel platformView)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var platform = _mapper.Map <Platform>(platformView);

            _platformService.AddPlatformTranslate(platformView.NameRu, "ru", _platformService.Get(platformView.OldName).Id);
            _platformService.Edit(platform, platformView.OldName);

            return(Ok(platform));
        }
        public void Update_ValidUpdatePlatformType_UpdateCalled()
        {
            var fakePlatformTypeViewModel = new PlatformTypeViewModel()
            {
                NameEn = "test"
            };
            var fakePlatformTypeDTO = _mapper.Map <ExtendPlatformTypeDTO>(fakePlatformTypeViewModel);

            _platformTypeService.Setup(service => service.IsUniqueEnName(It.IsAny <ExtendPlatformTypeDTO>()))
            .Returns(true);
            _platformTypeService.Setup(service => service.Update(fakePlatformTypeDTO));

            _sut.Update(fakePlatformTypeViewModel);

            _platformTypeService.Verify(s => s.Update(It.IsAny <ExtendPlatformTypeDTO>()), Times.Once);
        }
示例#9
0
        public IActionResult Create([FromForm] PlatformTypeViewModel platform)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var platformId    = Guid.NewGuid();
            var platformModel = new Platform {
                Name = platform.Name, Id = platformId
            };

            _platformService.Create(platformModel);
            _platformService.AddPlatformTranslate(platform.NameRu, "ru", platformId);

            return(StatusCode(StatusCodes.Status201Created));
        }
示例#10
0
        public ActionResult DeleteConfirmed(PlatformTypeViewModel model)
        {
            _platformTypeService.Delete(model.Id);

            return(RedirectToAction("GetAll"));
        }