Exemplo n.º 1
0
        public async Task <ActionResult> Create(CreateDivisionInput input)
        {
            if (ModelState.IsValid)
            {
                await _divisionAppService.CreateDivision(input);

                return(RedirectToAction("Index"));
            }
            else
            {
                var stations = _stationAppService.GetStations().Select(c => new SelectListItem {
                    Value = c.Id.ToString(), Text = c.Name
                });
                ViewBag.StationId = stations;
                return(View());
            }
        }
Exemplo n.º 2
0
        public async Task CreateDivision(CreateDivisionInput input)
        {
            //var Division = input.MapTo<Division>();

            var division = new Division
            {
                Name      = input.Name,
                StationId = input.StationId
            };

            var existingDivision = _divisionRepository.FirstOrDefault(p => p.Name == input.Name && p.StationId == input.StationId);

            if (existingDivision == null)
            {
                await _divisionRepository.InsertAsync(division);
            }
            else
            {
                throw new UserFriendlyException("There is already a Division with given name for the same station");
            }
        }