Example #1
0
        public ActionResult Create(DeviationModel model)
        {
            if(!ModelState.IsValid)
            {
                return View(model);
            }

            model.DeviationId = Guid.NewGuid();
            var mapper = new DeviationMapper();
            var entity = mapper.MapToEntity(model);
            DeviationRepository.AddItem(entity);
            DeviationRepository.Save();
            Bus.Send<CreateDeviationCommand>(cmd =>
                                             {
                                             	cmd.Id = entity.DeviationId;
                                             	cmd.DeviationName = entity.DeviationName;
                                             	cmd.DeviationTypeId = entity.DeviationTypeId;
                                             	cmd.ValidFrom = entity.DateInterval.ValidFrom;
                                             	cmd.ValidTo = entity.DateInterval.ValidTo;
                                             	cmd.Status = DeviationStatus.Created;
                                             }
                );

            return RedirectToAction("Index", "Home");
        }
Example #2
0
        public void TestMapperMapToEntity()
        {
            var model = new DeviationModel
            {
                ValidFrom = DateTime.Now,
                ValidTo = DateTime.Now.AddDays(12),
                DeviationTypeId = 1,
                DeviationName = "Timetable change today",
                DeviationId = Guid.NewGuid()
            };

            var mapper = new DeviationMapper();
            var entity = mapper.MapToEntity(model);

            Assert.AreEqual(entity.DeviationName, model.DeviationName);
            Assert.AreEqual(entity.DateInterval.ValidFrom, model.ValidFrom);
            Assert.AreEqual(entity.DateInterval.ValidTo, model.ValidTo);
        }
Example #3
0
        public ActionResult Edit(DeviationModel model)
        {
            if(!ModelState.IsValid)
                return View(model);

            var mapper = new DeviationMapper();
            var entity = mapper.MapToEntity(model);
            DeviationRepository.UpdateItem(entity);
            DeviationRepository.Save();

            Bus.Send<UpdateDeviationCommand>(cmd =>
                                             {
                                             	cmd.Id = entity.DeviationId;
                                             	cmd.DeviationName = entity.DeviationName;
                                             	cmd.DeviationTypeId = entity.DeviationTypeId;
                                             	cmd.ValidFrom = entity.DateInterval.ValidFrom;
                                             	cmd.ValidTo = entity.DateInterval.ValidTo;
                                             	cmd.Status = DeviationStatus.Updated;
                                             	cmd.HasBookings = model.HasBookings;
                                             });
            return RedirectToAction("Index", "Home");
        }
Example #4
0
 public ActionResult Create()
 {
     var model = new DeviationModel();
     return View(model);
 }