Exemplo n.º 1
0
        public IActionResult Edit(CourtLoadResetPeriod model)
        {
            ValidateModel(model);
            if (!ModelState.IsValid)
            {
                SetViewBag();
                return(View(nameof(Edit), model));
            }

            var currentId = model.Id;

            if (courtLoadPeriodService.CourtLoadResetPeriod_SaveData(model))
            {
                this.SaveLogOperation(currentId == 0, model.Id);
                SetSuccessMessage(MessageConstant.Values.SaveOK);
                return(RedirectToAction(nameof(Edit), new { id = model.Id }));
            }
            else
            {
                SetErrorMessage(MessageConstant.Values.SaveFailed);
            }
            SetViewBag();

            return(View(nameof(Edit), model));
        }
Exemplo n.º 2
0
 public bool CourtLoadResetPeriod_SaveData(CourtLoadResetPeriod model)
 {
     try
     {
         if (model.Id > 0)
         {
             var saved = repo.GetById <CourtLoadResetPeriod>(model.Id);
             saved.Description = model.Description;
             saved.DateFrom    = model.DateFrom;
             saved.DateTo      = model.DateTo.MakeEndDate();
             saved.UserId      = userContext.UserId;
             saved.DateWrt     = DateTime.Now;
             repo.Update(saved);
             repo.SaveChanges();
         }
         else
         {
             model.DateTo  = model.DateTo.MakeEndDate();
             model.UserId  = userContext.UserId;
             model.DateWrt = DateTime.Now;
             repo.Add(model);
             repo.SaveChanges();
         }
         return(true);
     }
     catch (Exception ex)
     {
         logger.LogError(ex, $"Грешка при запис на CourtLoadResetPeriod Id={ model.Id }");
         return(false);
     }
 }
Exemplo n.º 3
0
        /// <summary>
        /// Валидация преди запис на периоди към съд
        /// </summary>
        /// <param name="model"></param>
        void ValidateModel(CourtLoadResetPeriod model)
        {
            var lastLoadPeriods = courtLoadPeriodService.Get_CourtLoadResetPeriod_CrossPeriod(model);

            if (lastLoadPeriods.Count() > 0)
            {
                ModelState.AddModelError("", "Периода има сечение с друг период");
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// Добавяне на периоди към съд
        /// </summary>
        /// <returns></returns>
        public IActionResult Add()
        {
            var model = new CourtLoadResetPeriod()
            {
                CourtId  = userContext.CourtId,
                DateFrom = DateTime.Now
            };

            return(View(nameof(Edit), model));
        }
Exemplo n.º 5
0
        public IEnumerable <CourtLoadResetPeriod> Get_CourtLoadResetPeriod_CrossPeriod(CourtLoadResetPeriod newPeriod)
        {
            DateTime futureData = new DateTime(2100, 12, 31);

            return(repo.AllReadonly <CourtLoadResetPeriod>()
                   .Where(x => x.CourtId == newPeriod.CourtId)
                   .Where(x => x.Id != newPeriod.Id)
                   .Where(x => (((x.DateFrom >= newPeriod.DateFrom) && (x.DateFrom <= (newPeriod.DateTo ?? futureData))) || ((newPeriod.DateFrom >= x.DateFrom) && (newPeriod.DateFrom <= (x.DateTo ?? futureData)))))
                   .ToList());
        }