public ActionResult CreateNeedAssessment(NeedAssessment needAssessment, FormCollection collection) { ViewBag.Error = ""; var region = collection["RegionID"].ToString(CultureInfo.InvariantCulture); var regionID = int.Parse(region); int season = int.Parse(collection["SeasonID"].ToString(CultureInfo.InvariantCulture)); int typeOfNeedID = int.Parse(collection["TypeOfNeedID"].ToString(CultureInfo.InvariantCulture)); string planName = collection["Plan.PlanName"].ToString(CultureInfo.InvariantCulture); DateTime startDate = DateTime.Parse(collection["Plan.StartDate"].ToString(CultureInfo.InvariantCulture)); var firstDayOfTheMonth = startDate.AddDays(1 - startDate.Day); var duration = int.Parse(collection["Plan.Duration"].ToString(CultureInfo.InvariantCulture)); //DateTime endDate = DateTime.Parse(collection["Plan.EndDate"].ToString(CultureInfo.InvariantCulture)); var endDate = firstDayOfTheMonth.AddMonths(duration); if (ModelState.IsValid) { var existingPlan = _planService.FindBy(m => m.PlanName == planName && m.ProgramID == 1).FirstOrDefault(); if (existingPlan != null) { ModelState.AddModelError("Errors", @"Needs Assessment Name already Exists Please Change the Name"); } else { try { _planService.AddPlan(planName, firstDayOfTheMonth, endDate); var plan = _planService.Get(p => p.PlanName == planName).Single(); var userID = _needAssessmentHeaderService.GetUserProfileId(HttpContext.User.Identity.Name); _needAssessmentService.AddNeedAssessment(plan.PlanID, regionID, season, userID, typeOfNeedID); return(RedirectToAction("Index")); } catch (Exception exception) { var log = new Logger(); log.LogAllErrorsMesseges(exception, _log); ViewBag.Regions = new SelectList(_adminUnitService.FindBy(t => t.AdminUnitTypeID == 2), "AdminUnitID", "Name"); ViewBag.Season = new SelectList(_seasonService.GetAllSeason(), "SeasonID", "Name"); ViewBag.TypeOfNeed = new SelectList(_typeOfNeedAssessmentService.GetAllTypeOfNeedAssessment(), "TypeOfNeedAssessmentID", "TypeOfNeedAssessment1"); ViewBag.Error = "Need Assessment Already Exists Please Change Plan Name or Region Name"; ModelState.AddModelError("Errors", ViewBag.Error); return(View()); } } //return RedirectToAction("Edit", new { id = regionID, typeOfNeed = typeOfNeedID }); } ViewBag.Regions = new SelectList(_adminUnitService.FindBy(t => t.AdminUnitTypeID == 2), "AdminUnitID", "Name"); ViewBag.Season = new SelectList(_seasonService.GetAllSeason(), "SeasonID", "Name"); ViewBag.TypeOfNeed = new SelectList(_typeOfNeedAssessmentService.GetAllTypeOfNeedAssessment(), "TypeOfNeedAssessmentID", "TypeOfNeedAssessment1"); return(View(needAssessment)); }
public ActionResult AddNeedAssessment(NeedAssessment needAssessment, FormCollection collection) { var region = collection["RegionID"].ToString(CultureInfo.InvariantCulture); var regionID = int.Parse(region); int season = int.Parse(collection["SeasonID"].ToString(CultureInfo.InvariantCulture)); int planID = int.Parse(collection["PlanID"].ToString(CultureInfo.InvariantCulture)); int typeOfNeedID = int.Parse(collection["TypeOfNeedID"].ToString(CultureInfo.InvariantCulture)); var userID = _needAssessmentHeaderService.GetUserProfileId(HttpContext.User.Identity.Name); try { _needAssessmentService.AddNeedAssessment(needAssessment.PlanID, regionID, season, userID, typeOfNeedID); return(RedirectToAction("Detail", "NeedAssessment", new { id = needAssessment.PlanID })); } catch (Exception exception) { var log = new Logger(); log.LogAllErrorsMesseges(exception, _log); //ViewBag.Regions = new SelectList(_adminUnitService.FindBy(t => t.AdminUnitTypeID == 2), "AdminUnitID", "Name"); //ViewBag.Season = new SelectList(_seasonService.GetAllSeason(), "SeasonID", "Name"); //ViewBag.TypeOfNeed = new SelectList(_typeOfNeedAssessmentService.GetAllTypeOfNeedAssessment(), "TypeOfNeedAssessmentID", "TypeOfNeedAssessment1"); ViewBag.Error = "Need Assessment is already Created for this region"; //ModelState.AddModelError("Errors", ViewBag.Error); return(RedirectToAction("Detail", "NeedAssessment", new { id = needAssessment.PlanID })); } }
public ActionResult Create(HRD hrd) { var year = hrd.Year; var userID = _needAssessmentService.GetUserProfileId(HttpContext.User.Identity.Name); var seasonID = hrd.SeasonID.HasValue ? hrd.SeasonID.Value:1; var rationID = hrd.RationID; var planName = hrd.Plan.PlanName; var startDate = hrd.Plan.StartDate; var firstDayOfTheMonth = startDate.AddDays(1 - startDate.Day); var endDate = firstDayOfTheMonth.AddMonths(hrd.Plan.Duration).AddDays(-1); if (ModelState.IsValid) { var existingPlan = _planService.FindBy(m => m.PlanName == planName && m.ProgramID == 1).FirstOrDefault(); if (existingPlan != null) { ModelState.AddModelError("Errors", @"HRD Name already Exists Please Change HRD Name"); } else { try { _planService.AddHRDPlan(planName, firstDayOfTheMonth, endDate); var plan = _planService.FindBy(m => m.PlanName == planName).FirstOrDefault(); var planID = plan.PlanID; _hrdService.AddHRD(year, userID, seasonID, rationID, planID); return(RedirectToAction("Index")); } catch (Exception exception) { var log = new Logger(); log.LogAllErrorsMesseges(exception, _log); ModelState.AddModelError("Errors", @"Unable To Create New HRD"); //ViewBag.Error = "HRD for this Season and Year already Exists"; } } } ViewBag.Year = hrd.Year; ViewBag.RationID = new SelectList(_rationService.GetAllRation(), "RationID", "RefrenceNumber", hrd.RationID = 1); ViewBag.SeasonID = new SelectList(_seasonService.GetAllSeason(), "SeasonID", "Name"); return(View(hrd)); }