public PlanCreate CreateModelLoadSteps(PlanCreate model) { using (var ctx = new ApplicationDbContext()) { var query = ctx .Steps .Where(e => e.IsSaved == true) .Select(e => new StepListItem { StepId = e.StepId, StepType = e.StepType, Name = e.Name, ImageLink = e.ImageLink }).ToList(); var Meats = query.Where(m => m.StepType == Data.Steps.StepTypes.Meat).ToList(); var Cuts = query.Where(m => m.StepType == Data.Steps.StepTypes.Cut).ToList(); var CharcoalSetups = query.Where(m => m.StepType == Data.Steps.StepTypes.CharcoalSetup).ToList(); if (Meats.Count == 0 || Cuts.Count == 0 || CharcoalSetups.Count == 0) { throw new Exception(); } model.Meats = Meats; model.Cuts = Cuts; model.CharcoalSetups = CharcoalSetups; } return(model); }
public int?CreatePlan(PlanCreate model) { using (var ctx = new ApplicationDbContext()) { var stepOne = ctx .Steps .Single(o => o.StepId == model.StepOneId); var stepTwo = ctx .Steps .Single(o => o.StepId == model.StepTwoId); var stepThree = ctx .Steps .Single(o => o.StepId == model.StepThreeId); var entity = new Plan { UserId = _userId, Title = model.Title, StepOne = stepOne, StepTwo = stepTwo, StepThree = stepThree, IsSaved = true }; ctx.Plans.Add(entity); ctx.SaveChanges(); return(entity.PlanId); } }
public string Add(PlanCreate planCreate) { var p = PreparePlanCreate(planCreate); if (p == null) { return(null); } _ctx.Plans.Add(planCreate.Plan); return(planCreate.SubjectName); }
private PlanCreate PreparePlanCreate(PlanCreate planCreate) { planCreate.SubjectName = planCreate.SubjectName.Trim(); if (_ctx.Plans.Include(x => x.Subject).SingleOrDefault(x => x.Subject.Title.ToLower() == planCreate.SubjectName.ToLower() && planCreate.Plan.GroupId == x.GroupId && planCreate.Plan.PlanId != x.PlanId) != null) { return(null); } planCreate.Plan.Subject = _ctx.Subjects.SingleOrDefault(x => x.Title.ToLower() == planCreate.SubjectName.ToLower()) ?? new Subject { Title = planCreate.SubjectName }; return(planCreate); }
public ActionResult Create() { try { var service = CreatePlanService(); var model = new PlanCreate(); service.CreateModelLoadSteps(model); return(View(model)); } catch (Exception) { TempData["NeedSteps"] = "A Plan cannot be made if there are not at least one of each step."; return(RedirectToAction("Index")); } }
public string Edit(PlanCreate planCreate) { var p = PreparePlanCreate(planCreate); if (p == null) { return(null); } var plan = _ctx.Plans.Find(planCreate.Plan.PlanId); plan.LabH = p.Plan.LabH; plan.PracticeH = p.Plan.PracticeH; plan.LectionH = p.Plan.LectionH; plan.Subject = p.Plan.Subject; return(planCreate.SubjectName); }
public ActionResult Create(PlanCreate model) { var service = CreatePlanService(); if (!ModelState.IsValid) { return(View(service.CreateModelLoadSteps(model))); } int?newPlanId = service.CreatePlan(model); if (newPlanId != null) { TempData["SaveResult"] = "Your Plan was created."; return(RedirectToAction("KeyPoints", new { id = newPlanId })); } return(View(service.CreateModelLoadSteps(model))); }