public IQuestionnaire Add(IQuestion question, IBranch branch = null, bool here = false) { // the question already blongs to a quesstionnnaire if (question.Questionnaire != null) { throw new InvalidOperationException($"The {nameof(question)} already belongs to a questionnaire, cannot add it."); } question.Questionnaire = this; if (branch == null) { if (here) { this._questions.Insert(this.currentStep + 1, question); } else { this._questions.Add(question); } } else { if (here) { branch.Add(question, this.currentStep + 1); } else { branch.Add(question); } } return(this); }
public IActionResult Save(BranchIndexViewModel model) { var UserId = HttpContext.Session.GetString("UserId"); if (ModelState.IsValid) { var branch = new Branch { Id = model.Id, Description = model.Description, Company = _Branch.GetCompanyById(int.Parse(model.CompanyId)) }; if (model.Id.ToString().Equals("0")) { branch.CreatedBy = UserId; branch.CreationDate = DateTime.Now; _Branch.Add(branch); } else { branch.ModifiedBy = UserId; branch.ModifiedDate = DateTime.Now; _Branch.Update(branch); } return(RedirectToAction("Index")); } else { return(RedirectToAction("Index", model)); } }
public IActionResult Save(BranchViewModel model) { if (ModelState.IsValid) { var branch = new Branch { Id = model.Id, Description = model.Description, Company = _Branch.GetCompanyById(int.Parse(model.CompanyId)) }; if (model.Id.ToString().Length <= 0) { _Branch.Add(branch); } else { _Branch.Update(branch); } } return(View()); }