コード例 #1
0
        public ActionResult Edit(EvaluationFormViewModel evaluationForm)
        {
            //if (ModelState.IsValid)
            //{
            var Mysection = db.EvaluationForm.Find(evaluationForm.id);

            Mysection.year     = evaluationForm.year;
            Mysection.iscurent = evaluationForm.iscurent;


            foreach (var item in db.EvaluaationFormtoSections)
            {
                if (item.EvaluationFormID == evaluationForm.id)
                {
                    foreach (var item2 in evaluationForm.Sections)
                    {
                        if (item.SectionsID == item2.Id)
                        {
                            if (item2.Checked)
                            {
                            }
                            else
                            {
                                db.Entry(item).State = System.Data.Entity.EntityState.Deleted;
                            }
                        }
                    }
                }
            }
            bool A = true;

            foreach (var item in evaluationForm.Sections)
            {
                if (item.Checked)
                {
                    foreach (var item2 in db.EvaluaationFormtoSections)
                    {
                        if (item.Id == item2.SectionsID && evaluationForm.id == item2.EvaluationFormID)
                        {
                            A = false;
                        }
                    }
                    if (A)
                    {
                        db.EvaluaationFormtoSections.Add(new EvaluaationFormtoSections {
                            EvaluationFormID = evaluationForm.id, SectionsID = item.Id
                        });
                    }
                    A = true;
                }
            }


            db.SaveChanges();
            return(RedirectToAction("Index"));

            //  }
            return(View(evaluationForm));
        }
コード例 #2
0
        public IActionResult Evaluate(int id)
        {
            var eval = evaluationsService.GetEvaluationById(id);
            EvaluationFormViewModel formVM = new EvaluationFormViewModel();

            formVM.Id             = eval.Id;
            formVM.Sections       = eval.Sections;
            formVM.FormName       = eval.FormName;
            formVM.EvaluationName = eval.EvaluationName;
            formVM.EmployeeName   = employeesService.GetEmployeeInfo(eval.EmployeeId).Name;
            formVM.IsCompleted    = eval.IsCompleted;
            formVM.SectionScales  = new Dictionary <int, SectionScaleViewModel>();
            //NOTE: each section has its own scale

            foreach (var section in eval.Sections)
            {
                var sectionScale = section.EvaluationScale;
                if (sectionScale != null)
                {
                    var scaleOptions   = evaluationsService.GetEvaluationScaleOptionsFromScale(sectionScale.Id);
                    var scaleOptionsVM = new SectionScaleViewModel()
                    {
                        SectionId = section.Id
                    };
                    var options = new List <SelectListItem>();
                    options.Add(new SelectListItem()
                    {
                        Value = "0", Text = "Not Evaluated"
                    });

                    options.AddRange(scaleOptions.Select(option =>
                                                         new SelectListItem
                    {
                        Value = "" + option.Id,
                        Text  = option.Name
                    })
                                     .ToList());
                    scaleOptionsVM.ScaleOptions = options;

                    formVM.SectionScales[section.Id] = scaleOptionsVM;
                }
            }

            return(View("EvaluationForm", formVM));
        }
コード例 #3
0
        // GET: EvaluationForms/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            EvaluationForm evaluationForm = db.EvaluationForm.Find(id);

            if (evaluationForm == null)
            {
                return(HttpNotFound());
            }
            var R = from b in db.Sections
                    select new
            {
                b.Id,
                b.SectionName,
                b.Description,
                b.TotalPoints,

                Checked = ((from ab in db.EvaluaationFormtoSections
                            where (ab.EvaluationFormID == id) & (ab.SectionsID == b.Id)
                            select ab).Count() > 0)
            };
            var Myviewmodel = new EvaluationFormViewModel();

            Myviewmodel.id       = id.Value;
            Myviewmodel.year     = evaluationForm.year;
            Myviewmodel.iscurent = evaluationForm.iscurent;



            var Myviewmodel2 = new List <CheckSectionsViewModel>();

            foreach (var item in R)
            {
                Myviewmodel2.Add(new CheckSectionsViewModel {
                    Id = item.Id, SectionName = item.SectionName, Description = item.Description, TotalPoints = item.TotalPoints, Checked = item.Checked
                });
            }
            Myviewmodel.Sections = Myviewmodel2;

            return(View(Myviewmodel));
        }