public async Task <IActionResult> Create(SRSObjectIndustrialInputModel model)
        {
            try
            {
                if (!this.ModelState.IsValid)
                {
                    model.DistrictItems = this.districtService.GetAllAsKeyValuePairs();
                    return(this.View(model));
                }

                if (model.DistrictId == 0)
                {
                    model.DistrictItems = this.districtService.GetAllAsKeyValuePairs();
                    this.ModelState.AddModelError(string.Empty, "Please fill districts!");
                    return(this.View(model));
                }

                var user = await this.userManager.GetUserAsync(this.User);

                await this.srsObjectIndustrialService.CreateAsync(model, user.Id);

                this.TempData["Message"] = "SRS Object Industrial was added successfully.";

                return(this.RedirectToAction("All"));
            }
            catch (Exception ex)
            {
                this.ModelState.AddModelError(string.Empty, ex.Message);
                return(this.View());
            }
        }
        public IActionResult Create()
        {
            var viewModel = new SRSObjectIndustrialInputModel();

            viewModel.DistrictItems = this.districtService.GetAllAsKeyValuePairs();
            return(this.View(viewModel));
        }
Exemple #3
0
        public async Task CreateAsync(SRSObjectIndustrialInputModel input, string userId)
        {
            var srsobjectIndustrial = new SrsobjectIndustrial
            {
                Name          = input.Name,
                Address       = input.Address,
                ContactPerson = input.ContactPerson,
                Note          = input.Note,
                EntryDate     = input.EntryDate,
                DistrictId    = input.DistrictId,
                AddedByUserId = userId,
            };

            await this.srsObjectIndurstiralRepository.AddAsync(srsobjectIndustrial);

            await this.srsObjectIndurstiralRepository.SaveChangesAsync();
        }