public ActionResult CreateNewProgress(FollowupProgressModel model) { PrePurchase_FollowUp_Plan plan = new PrePurchase_FollowUp_Plan(); plan.Description = model.Desription; plan.name = model.Name; plan.isActive = true; plan.isOperation = false; plan.productID = model.productID; plan.createDate = DateTime.Today; SSMEntities se = new SSMEntities(); se.PrePurchase_FollowUp_Plan.Add(plan); se.SaveChanges(); foreach (Plan_Step step in model.steps.ToList()) { if (step.StepEmailContent == null) { model.steps.Remove(step); } else if (step.StepEmailContent.Trim().Length == 0) { model.steps.Remove(step); } } for (int i = 0; i < model.steps.Count(); i++) { Plan_Step step = model.steps[i]; step.stepNo = (i + 1); step.planID = plan.id; se.Plan_Step.Add(step); se.SaveChanges(); } for (int i = 0; i < model.steps.Count(); i++) { Plan_Step step = model.steps[i]; if (i != 0) { step.previousStep = model.steps[i - 1].id; } if (i != model.steps.Count() - 1) { step.nextStep = model.steps[i + 1].id; } se.SaveChanges(); } return(RedirectToAction("Detail", new { id = model.productID })); }
public FollowupProgressModel() { steps = new List <Plan_Step>(); int count = steps.Count(); for (int i = count + 1; i < 9; i++) { Plan_Step step = new Plan_Step(); step.stepNo = i; step.TimeFromLastStep = 0; steps.Add(step); } }
public FollowupProgressModel(PrePurchase_FollowUp_Plan plan) { this.Name = plan.name; this.id = plan.id; this.Desription = plan.Description; this.productID = plan.productID; steps = new List <Plan_Step>(); foreach (Plan_Step step in plan.Plan_Step) { steps.Add(step); } int count = steps.Count(); for (int i = count + 1; i < 9; i++) { Plan_Step step = new Plan_Step(); step.stepNo = i; step.TimeFromLastStep = 0; steps.Add(step); } count = steps.Count(); }
public ActionResult FinishEditProgress(FollowupProgressModel model) { SSMEntities se = new SSMEntities(); PrePurchase_FollowUp_Plan plan = se.PrePurchase_FollowUp_Plan.Find(model.id); if (plan != null) { plan.name = model.Name; plan.Description = model.Desription; plan.lastUpdate = DateTime.Today; foreach (Plan_Step step in plan.Plan_Step.ToList()) { step.previousStep = null; step.nextStep = null; se.SaveChanges(); se.Plan_Step.Remove(step); } int index = 1; for (int i = 1; i < model.steps.Count() + 1; i++) { Plan_Step step = model.steps[i - 1]; if (step.StepEmailContent != null) { step.planID = plan.id; step.stepNo = i; se.Plan_Step.Add(step); se.SaveChanges(); index = index + 1; } else { model.steps.Remove(step); } } for (int i = 1; i < model.steps.Count() + 1; i++) { Plan_Step step = model.steps[i - 1]; try { step.previousStep = model.steps[i - 2].id; } catch (Exception e) { step.previousStep = null; } try { step.nextStep = model.steps[i].id; } catch (Exception e) { step.nextStep = null; } try { if (step.previousStep == 0) { step.previousStep = null; } } catch (Exception e) { } try { if (step.nextStep == 0) { step.nextStep = null; } } catch (Exception e) { } se.SaveChanges(); } } return(RedirectToAction("EditPlan", new { planID = plan.id })); }