コード例 #1
0
        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);
        }
コード例 #2
0
        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));
            }
        }
コード例 #3
0
 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());
 }