示例#1
0
        public ActionResult Create(VmGrade model)
        {
            var result  = -1;
            var blGrade = new BLGrade();

            model.CurrentUserId = CurrentUserId;

            try
            {
                if (ModelState.IsValid)
                {
                    result = blGrade.CreateGrade(model);
                }
            }
            catch (Exception ex)
            {
                result = -1;
            }

            if (result != -1)
            {
                return(RedirectToAction("gl", "Admin", new { activeItemId = result }));
            }

            model.ActionMessageHandler.Message = "Operation has been failed...\n";

            return(View("../Admin/CreateGrade", model));
        }
示例#2
0
        public VmGrade GetGradeById(int id)
        {
            var gradeRepository = UnitOfWork.GetRepository <GradeRepository>();

            var grade = gradeRepository.GetGradeById(id);

            var vmGrade = new VmGrade
            {
                Id   = grade.Id,
                Name = grade.Name,
            };

            return(vmGrade);
        }
示例#3
0
        public bool UpdateGrade(VmGrade vmGrade)
        {
            try
            {
                //var viewTeamGradeDetailRepository = UnitOfWork.GetRepository<ViewTeamGradeDetailRepository>();
                //if (viewTeamGradeDetailRepository.GetTeamGradeDetailsCountByGraeId(vmGrade.Id) > 0)
                //{
                //    return false;
                //}

                var gradeRepository = UnitOfWork.GetRepository <GradeRepository>();

                var newGradeDetailList = new List <GradeDetail>();
                var i            = 0;
                var Points       = vmGrade.Points.Split(new char[] { '■' }, StringSplitOptions.RemoveEmptyEntries);
                var Coefficients = vmGrade.Coefficients.Split(new char[] { '■' }, StringSplitOptions.RemoveEmptyEntries);

                foreach (var item in vmGrade.EvaluationItems.Split(new char[] { '■' }, StringSplitOptions.RemoveEmptyEntries))
                {
                    newGradeDetailList.Add(new GradeDetail
                    {
                        EvaluationItem = item,
                        Point          = double.Parse(Points[i]),
                        Coefficient    = double.Parse(Coefficients[i]),
                    });
                    i++;
                }

                var updateableGrade = new Grade
                {
                    Id           = vmGrade.Id,
                    Name         = vmGrade.Name,
                    GradeDetails = newGradeDetailList
                };

                var gradeDetailRepository = UnitOfWork.GetRepository <GradeDetailRepository>();

                gradeDetailRepository.DeleteGradeDetailsByGrade(vmGrade.Id);

                gradeRepository.UpdateGrade(updateableGrade);

                return(UnitOfWork.Commit());
            }
            catch (Exception ex)
            {
                return(false);
            }
        }
示例#4
0
        public int CreateGrade(VmGrade vmGrade)
        {
            var result = -1;

            try
            {
                var Points       = vmGrade.Points.Split(new char[] { '■' }, StringSplitOptions.RemoveEmptyEntries);
                var Coefficients = vmGrade.Coefficients.Split(new char[] { '■' }, StringSplitOptions.RemoveEmptyEntries);

                var gradeRepository = UnitOfWork.GetRepository <GradeRepository>();

                var newGradeDetailList = new List <GradeDetail>();
                var i = 0;
                foreach (var item in vmGrade.EvaluationItems.Split(new char[] { '■' }, StringSplitOptions.RemoveEmptyEntries))
                {
                    newGradeDetailList.Add(new GradeDetail
                    {
                        EvaluationItem = item,
                        Point          = double.Parse(Points[i]),
                        Coefficient    = double.Parse(Coefficients[i]),
                    });
                    i++;
                }
                var newGrade = new Grade
                {
                    Id           = vmGrade.Id,
                    Name         = vmGrade.Name,
                    GradeDetails = newGradeDetailList
                };

                gradeRepository.CreateGrade(newGrade);

                UnitOfWork.Commit();

                result = newGrade.Id;
            }
            catch (Exception ex)
            {
                result = -1;
            }

            return(result);
        }
示例#5
0
        public VmGrade GetGradeWithDetailsById(int id)
        {
            var viewGradeDetailRepository = UnitOfWork.GetRepository <ViewGradeDetailRepository>();

            var gradeDetails = viewGradeDetailRepository.GetGradeDetailsByGrade(id);

            var evaluationItems = string.Join("■", from e in gradeDetails select e.EvaluationItem);
            var points          = string.Join("■", from e in gradeDetails select e.Point);
            var coefficients    = string.Join("■", from e in gradeDetails select e.Coefficient);

            var vmGrade = new VmGrade
            {
                Id              = gradeDetails.First().Id,
                Name            = gradeDetails.First().Name,
                EvaluationItems = evaluationItems,
                Points          = points,
                Coefficients    = coefficients,
            };

            return(vmGrade);
        }
示例#6
0
        public ActionResult EditGrade(VmGrade model)
        {
            model.CurrentUserId = CurrentUserId;

            var result  = true;
            var blGrade = new BLGrade();

            try
            {
                if (ModelState.IsValid)
                {
                    result = blGrade.UpdateGrade(model);
                }
            }
            catch (Exception ex)
            {
                result = false;
            }

            if (result == false)
            {
                model.ActionMessageHandler.Message = "Operation has been failed...\n call system Admin";
            }
            else
            {
                model.ActionMessageHandler.Message = "Operation has been succeeded";
            }

            var jsonData = new
            {
                success = result,
                message = model.ActionMessageHandler.Message
            };

            return(Json(jsonData, JsonRequestBehavior.AllowGet));
        }