public ActionResult Create(FormCollection form, CreateDealerInput input, HttpPostedFileBase tin_file, HttpPostedFileBase bl_file) { if (ModelState.IsValid) { if (tin_file != null && bl_file != null) { } var user = _userAppService.GetLoggedInUser(); input.StationId = user.StationId; //get user logged in station int Id = _dealerAppService.CreateDealer(input); //update selected candidate if exists if (form.AllKeys.Contains("CandidateId") && !string.IsNullOrEmpty(form.Get("CandidateId").ToString())) { var candidate = _candidateAppService.GetCandidate(Convert.ToInt32(form.Get("CandidateId"))); _candidateAppService.RegisterCandidate(candidate); } return(RedirectToAction("Create", "DealerActivities", new { id = Id })); } else { var stations = _stationAppService.GetStations().Select(c => new SelectListItem { Value = c.Id.ToString(), Text = c.Name }); ViewBag.StationId = stations; return(View()); } }
public int CreateDealer(CreateDealerInput input) { //get current active financial year; var current = _financialYearRepository.FirstOrDefault(c => c.IsActive == true); if (current != null) { var dealer = new Dealer { SerialNumber = input.SerialNumber, ApplicantId = input.ApplicantId, StationId = input.StationId, FinancialYearId = current.Id, }; var existingDealer = _dealerRepository.FirstOrDefault(p => p.SerialNumber == input.SerialNumber && p.FinancialYearId == current.Id); if (existingDealer == null) { var dealerId = _dealerRepository.InsertAndGetId(dealer); return(dealerId); } else { throw new UserFriendlyException("There is already a Dealer with given name"); } } else { throw new UserFriendlyException("No Active Financial Year"); } }
public ActionResult ApplyForRegistration(CreateDealerInput input) { try { if (ModelState.IsValid) { if (_dealerAppService.IsApplicationExists(input.ApplicantId, _financialYearAppService.GetActiveFinancialYear())) { TempData["danger"] = string.Format(@"Your have already submitted application for current financial year ""{0}"" !", _financialYearAppService.GetActiveFinancialYear().Name); return(RedirectToAction("Index", "Dashboard")); } else { int DealerId = _dealerAppService.CreateDealer(input); TempData["success"] = string.Format(@"The Application has been successfully created!."); return(RedirectToAction("AddActivities", new { Id = DealerId })); } } else { var applicant = _applicantService.GetApplicantById(_userAppService.GetLoggedInUser().ApplicantId); var Station = _stationAppService.GetStations().Select(c => new SelectListItem { Value = c.Id.ToString(), Text = c.Name }); ViewBag.Applicant = applicant; ViewBag.StationId = Station; ViewBag.SerialNumber = RandomSerialNumbers(); return(View()); } }catch (Exception ex) { var applicant = _applicantService.GetApplicantById(_userAppService.GetLoggedInUser().ApplicantId); var Station = _stationAppService.GetStations().Select(c => new SelectListItem { Value = c.Id.ToString(), Text = c.Name }); ViewBag.Applicant = applicant; ViewBag.StationId = Station; ViewBag.SerialNumber = RandomSerialNumbers(); ModelState.AddModelError("danger", ex.Message); return(View()); } }