示例#1
0
        public async Task <ActionResult> Create(AddRegionViewModel addRegionVm)
        {
            if (!ModelState.IsValid)
            {
                Alert("Invalid Request", NotificationType.error, Int32.Parse(_appConfig.Value.NotificationDisplayTime));
                return(View());
            }
            try
            {
                // TODO: Add insert logic here
                var addRegionRequest = new AddRegionRequest {
                    Name = addRegionVm.Name, Description = addRegionVm.Description
                };
                var result = await _regionService.Create(addRegionRequest);

                if (result.Success)
                {
                    Alert($"Region Created Successfully", NotificationType.success, Int32.Parse(_appConfig.Value.NotificationDisplayTime));
                    return(RedirectToAction(nameof(Index)));
                }
                else
                {
                    Alert($"Error: {result.Message}", NotificationType.error, Int32.Parse(_appConfig.Value.NotificationDisplayTime));
                    return(View());
                }
            }
            catch
            {
                Alert($"Error Occurred While processing the request", NotificationType.error, Int32.Parse(_appConfig.Value.NotificationDisplayTime));
                return(View());
            }
        }
示例#2
0
        public async Task <ActionResult> CreateRegion(AddRegionViewModel request)
        {
            if (!ModelState.IsValid)
            {
                Alert($"Invalid Request.", NotificationType.error, Int32.Parse(_appConfig.Value.NotificationDisplayTime));
                return(RedirectToAction(nameof(Regions), new { id = request.CountryId }));
            }
            try
            {
                var addRegionRequest = new AddRegionRequest {
                    CountryId = request.CountryId, Name = request.Name, Description = request.Description
                };
                var result = await _regionService.Create(addRegionRequest);

                if (!result.Success)
                {
                    Alert($"{result.Message}", NotificationType.info, Int32.Parse(_appConfig.Value.NotificationDisplayTime));
                    return(RedirectToAction(nameof(Regions), new { id = request.CountryId }));
                }
                Alert($"Region Created Successfully", NotificationType.success, Int32.Parse(_appConfig.Value.NotificationDisplayTime));
                return(RedirectToAction(nameof(Regions), new { id = request.CountryId }));
            }
            catch (Exception ex)
            {
                Alert($"Error! {ex.Message}.", NotificationType.error, Int32.Parse(_appConfig.Value.NotificationDisplayTime));
                return(RedirectToAction(nameof(Regions), new { id = request.CountryId }));
            }
        }
        public async Task <IActionResult> Add(AddRegionViewModel model)
        {
            if (!string.IsNullOrWhiteSpace(model.Name) && await regionService.ExistsAsync(model.Name))
            {
                ModelState.AddModelError(nameof(model.Name), "Region with the same name already exists.");
            }

            if (!await countryService.ExistsAsync(model.CountryId))
            {
                ModelState.AddModelError(nameof(model.CountryId), $"There is no country with id '{model.CountryId}'");
            }

            if (!ModelState.IsValid)
            {
                model.Countries = await GetCountries();

                return(View(model));
            }

            var id = await regionService.AddAsync(model.Name, model.Description, model.CountryId);

            if (id < 1)
            {
                ModelState.AddModelError(string.Empty, "Save failed.");
                model.Countries = await GetCountries();

                return(View(model));
            }

            return(RedirectToAction(nameof(Add)));
        }
示例#4
0
        public ActionResult CreateRegion(Guid countryId, string countryName)
        {
            var regionVm = new AddRegionViewModel {
                CountryId = countryId
            };

            ViewBag.CountryName = countryName;
            return(View(regionVm));
        }
        public ActionResult AddRegion(AddRegionViewModel model)
        {
            if (ModelState.IsValid)
            {
                if (!regionService.IsContains(model.name))
                {
                    regionService.Add(model.name);

                    return(this.RedirectToAction("Index"));
                }

                ModelState.AddModelError("dublicate", "Този Регион вече съществува!");
            }

            return(this.View(model));
        }
 public Task AddRegionAsync(AddRegionViewModel model, string userName)
 {
     throw new System.NotImplementedException();
 }