Пример #1
0
        public IActionResult EditTypeUnit(CaseTypeUnitEditVM model)
        {
            if (!ModelState.IsValid)
            {
                return(View(nameof(EditTypeUnit), model));
            }

            string _isvalid = IsValidTypeUnit(model);

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

            var currentId = model.Id;

            if (service.CaseTypeUnit_SaveData(model))
            {
                this.SaveLogOperation(currentId == 0, model.Id);
                SetSuccessMessage(MessageConstant.Values.SaveOK);
                return(RedirectToAction(nameof(EditTypeUnit), new { id = model.Id }));
            }
            else
            {
                SetErrorMessage(MessageConstant.Values.SaveFailed);
            }
            return(View(nameof(EditTypeUnit), model));
        }
Пример #2
0
        /// <summary>
        /// Добавяне на състав към точен вид дело
        /// </summary>
        /// <param name="caseTypeId"></param>
        /// <returns></returns>
        public IActionResult AddTypeUnit(int caseTypeId)
        {
            var model = new CaseTypeUnitEditVM()
            {
                CaseTypeId         = caseTypeId,
                IsActive           = true,
                CaseTypeUnitCounts = service.GetList_CaseTypeUnitCounts()
            };

            return(View(nameof(EditTypeUnit), model));
        }
Пример #3
0
        /// <summary>
        /// Валидация преди запис на състав
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        private string IsValidTypeUnit(CaseTypeUnitEditVM model)
        {
            if (model.Label == string.Empty)
            {
                return("Няма въведено име");
            }

            if (!model.CaseTypeUnitCounts.Any(x => x.Value > 0))
            {
                return("Няма въведена поне 1бройка за състава");
            }

            return(string.Empty);
        }
Пример #4
0
        /// <summary>
        /// Запис на състав към точен вид дело
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public bool CaseTypeUnit_SaveData(CaseTypeUnitEditVM model)
        {
            try
            {
                var saved = (model.Id > 0) ? repo.GetById <CaseTypeUnit>(model.Id) : new CaseTypeUnit();
                saved.CaseTypeId  = model.CaseTypeId;
                saved.Label       = model.Label;
                saved.Description = model.Description;
                saved.IsActive    = model.IsActive;
                saved.DateStart   = model.DateStart;
                saved.DateEnd     = model.DateEnd;

                if (model.Id > 0)
                {
                    repo.Update(saved);

                    var caseTypeUnits = repo.AllReadonly <CaseTypeUnitCount>()
                                        .Where(x => x.CaseTypeUnitId == saved.Id)
                                        .ToList();
                    repo.DeleteRange(caseTypeUnits);
                }
                else
                {
                    repo.Add <CaseTypeUnit>(saved);
                    repo.SaveChanges();
                    saved.OrderNumber = saved.Id;
                }

                var caseTypeUnitCounts = FillList_TypeUnitCount(model.CaseTypeUnitCounts.ToList(), saved.Id);
                repo.AddRange(caseTypeUnitCounts);

                repo.SaveChanges();
                model.Id = saved.Id;
                return(true);
            }
            catch (Exception ex)
            {
                logger.LogError(ex, $"Грешка при запис на интервал по дело Id={ model.Id }");
                return(false);
            }
        }