Ejemplo n.º 1
0
        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));
        }
Ejemplo n.º 2
0
 public async Task <ActionResult <PlanDto> > CreatePlan(PlanDto plan)
 {
     try
     {
         if (plan == null)
         {
             return(BadRequest());
         }
         return(await _planService.AddPlan(plan));
     }
     catch (Exception)
     {
         return(StatusCode(StatusCodes.Status500InternalServerError, "Error retrieving data from the database"));
     }
 }
Ejemplo n.º 3
0
        public ActionResult Create(Plan plan)
        {
            var startDate          = plan.StartDate;
            var firstDayOfTheMonth = startDate.AddDays(1 - startDate.Day);
            var endDate            = firstDayOfTheMonth.AddMonths(plan.Duration).AddDays(-1);

            if (ModelState.IsValid)
            {
                var existingPlan =
                    _planService.FindBy(m => m.PlanName == plan.PlanName && m.ProgramID == plan.ProgramID)
                    .FirstOrDefault();
                if (existingPlan != null)
                {
                    ModelState.AddModelError("Errors", @"Plan with this Name and Program already Exists please change Plan Name");
                }
                else
                {
                    try
                    {
                        plan.StartDate = firstDayOfTheMonth;
                        plan.EndDate   = endDate;
                        plan.Status    = (int)PlanStatus.Draft;
                        _planService.AddPlan(plan);
                        return(RedirectToAction("Index"));
                    }
                    catch (Exception ex)
                    {
                        ModelState.AddModelError("Errors", @"Plan with this name already Existed");
                        ViewBag.ProgramID = new SelectList(_planService.GetPrograms(), "ProgramID", "Name");
                        return(View(plan));
                    }
                }
            }
            ViewBag.ProgramID = new SelectList(_planService.GetPrograms(), "ProgramID", "Name");
            return(View(plan));
        }