示例#1
0
        private string IsValid(CourtDepartmentLawUnit model)
        {
            if (model.LawUnitId < 0)
            {
                return("Няма избрано лице");
            }

            if ((model.JudgeDepartmentRoleId ?? 0) < 1)
            {
                return("Няма избрана роля");
            }

            var courtDepartmentLaws = service.CourtDepartmentLawUnit_Select(model.CourtDepartmentId).ToList();

            if (courtDepartmentLaws.Any(x => (x.LawUnitId == model.LawUnitId) &&
                                        ((model.Id > 0) ? x.Id != model.Id : true)))
            {
                return("Този съдия е добавен");
            }

            if (courtDepartmentLaws.Any(x => (x.JudgeDepartmentRoleId == NomenclatureConstants.JudgeDepartmentRole.Predsedatel) &&
                                        ((model.Id > 0) ? x.Id != model.Id : true)) && model.JudgeDepartmentRoleId == NomenclatureConstants.JudgeDepartmentRole.Predsedatel)
            {
                return("Има избран председател");
            }

            return(string.Empty);
        }
示例#2
0
        public IActionResult EditLawUnit(CourtDepartmentLawUnit model)
        {
            SetViewbagLawUnit(model.CourtDepartmentId);
            if (!ModelState.IsValid)
            {
                return(View(nameof(EditLawUnit), model));
            }

            string _isvalid = IsValid(model);

            if (_isvalid != string.Empty)
            {
                SetErrorMessage(_isvalid);
                return(View(nameof(EditLawUnit), model));
            }

            var currentId = model.Id;

            if (service.CourtDepartmentLawUnit_SaveData(model))
            {
                this.SaveLogOperation(currentId == 0, model.Id);
                SetSuccessMessage(MessageConstant.Values.SaveOK);
                return(RedirectToAction(nameof(EditLawUnit), new { id = model.Id }));
            }
            else
            {
                SetErrorMessage(MessageConstant.Values.SaveFailed);
            }
            return(View(nameof(EditLawUnit), model));
        }
 public bool CourtDepartmentLawUnit_SaveData(CourtDepartmentLawUnit model)
 {
     try
     {
         if (model.Id > 0)
         {
             //Update
             var saved = repo.GetById <CourtDepartmentLawUnit>(model.Id);
             saved.CourtDepartmentId     = model.CourtDepartmentId;
             saved.LawUnitId             = model.LawUnitId;
             saved.JudgeDepartmentRoleId = model.JudgeDepartmentRoleId;
             //saved.DateFrom = model.DateFrom;
             //saved.DateTo = model.DateTo;
             repo.Update(saved);
             repo.SaveChanges();
         }
         else
         {
             model.DateFrom = DateTime.Now.Date;
             //Insert
             repo.Add <CourtDepartmentLawUnit>(model);
             repo.SaveChanges();
         }
         return(true);
     }
     catch (Exception ex)
     {
         logger.LogError(ex, $"Грешка при запис на Съдебни нива - съдии Id={ model.Id }");
         return(false);
     }
 }
示例#4
0
        public IActionResult AddLawUnit(int CourtDepartmentId)
        {
            var model = new CourtDepartmentLawUnit()
            {
                CourtDepartmentId = CourtDepartmentId,
                //DateFrom = DateTime.Now
            };

            SetViewbagLawUnit(CourtDepartmentId);
            return(View(nameof(EditLawUnit), model));
        }
        /// <summary>
        /// Формиране на списък и извикване на функцията за запис в CourtDepartmentLawUnit
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public bool CourtDepartmentLawUnit_SaveData(CheckListViewVM model)
        {
            #region Попълване на данните за запис
            List <CourtDepartmentLawUnit> courtDepartmentLowUnits = CourtDepartmentLowUnit_Select(model.ObjectId).ToList();

            // сетване на всички до днешна дата без 1 секунда
            // courtDepartmentLowUnits.ToList().ForEach(x => x.DateTo = DateTime.Now.AddSeconds(-1));

            List <CourtDepartmentLawUnit> courtDepartmentLawUnitNews = new List <CourtDepartmentLawUnit>();

            // въртя списъка с елементи визуализирани на екрана
            foreach (var check in model.checkListVMs)
            {
                // търси елемента от екрана в списъка с записани елементи
                var court = courtDepartmentLowUnits.Where(x => x.LawUnitId == int.Parse(check.Value))
                            .Where(x => x.DateTo == null)
                            .DefaultIfEmpty(null).FirstOrDefault();

                if (court != null)
                {
                    // ако  го е намерил

                    if (check.Checked)
                    {
                        //ако е маркирано в екрана
                        if ((court.DateTo != null) && (court.DateTo <= DateTime.Now))
                        {
                            court.DateTo = null;
                        }
                    }
                    else
                    {
                        // ако не е маркирано в екрана
                        if (court.DateTo == null)
                        {
                            court.DateTo = DateTime.Now.AddSeconds(-1);
                        }
                    }
                }
                else
                {
                    // ако ne go е намерен в записаните елементи
                    if (check.Checked)
                    {
                        // ако е маркиран
                        CourtDepartmentLawUnit courtDepartmentLawUnit = new CourtDepartmentLawUnit
                        {
                            CourtDepartmentId = model.ObjectId,
                            LawUnitId         = int.Parse(check.Value),
                            DateFrom          = DateTime.Now
                        };

                        courtDepartmentLawUnitNews.Add(courtDepartmentLawUnit);
                    }
                }
            }

            courtDepartmentLowUnits.AddRange(courtDepartmentLawUnitNews);
            #endregion

            #region Запис на данните

            return(SaveLawUnit(courtDepartmentLowUnits));

            #endregion
        }