Ejemplo n.º 1
0
        /// <summary>
        /// Добавяне на брояч
        /// </summary>
        /// <returns></returns>
        public IActionResult Add()
        {
            SetBreadcrums(0);
            var model = new CounterEditVM()
            {
                CourtId = userContext.CourtId
            };

            SetViewbag();
            return(View(nameof(Edit), model));
        }
Ejemplo n.º 2
0
        public CounterEditVM Counter_GetById(int id)
        {
            CounterEditVM result = repo.AllReadonly <Counter>(x => x.Id == id)
                                   .Select(x => new CounterEditVM()
            {
                Id            = x.Id,
                CourtId       = x.CourtId,
                Label         = x.Label,
                CounterTypeId = x.CounterTypeId,
                ResetTypeId   = x.ResetTypeId,
                Prefix        = x.Prefix,
                Suffix        = x.Suffix,
                DigitCount    = x.DigitCount,
                InitValue     = x.InitValue,
            }).FirstOrDefault();

            switch (result.CounterTypeId)
            {
            case NomenclatureConstants.CounterTypes.Document:
                var _counterDoc = repo.AllReadonly <CounterDocument>(x => x.CounterId == id).FirstOrDefault();
                if (_counterDoc != null)
                {
                    result.DocumentDirectionId = _counterDoc.DocumentDirectionId;
                }
                break;

            case NomenclatureConstants.CounterTypes.Case:
                var _counterCase = repo.AllReadonly <CounterCase>(x => x.CounterId == id).FirstOrDefault();
                if (_counterCase != null)
                {
                    result.CaseGroupId = _counterCase.CaseGroupId;
                }
                break;

            case NomenclatureConstants.CounterTypes.SessionAct:
                var _counterAct = repo.AllReadonly <CounterSessionAct>(x => x.CounterId == id).FirstOrDefault();
                if (_counterAct != null)
                {
                    result.SessionActGroupId = _counterAct.SessionActGroupId;
                }
                break;
            }
            return(result);
        }
Ejemplo n.º 3
0
        public IActionResult Edit(CounterEditVM model)
        {
            SetViewbag();
            if (!ModelState.IsValid)
            {
                SetBreadcrums(model.Id);
                return(View(nameof(Edit), model));
            }
            var currentId = model.Id;

            if (service.Counter_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);
            }
            SetBreadcrums(model.Id);
            return(View(nameof(Edit), model));
        }
Ejemplo n.º 4
0
 public bool Counter_SaveData(CounterEditVM model)
 {
     throw new NotImplementedException();
 }
Ejemplo n.º 5
0
        public bool Counter_SaveData(CounterEditVM model)
        {
            try
            {
                if (model.Id > 0)
                {
                    //Update
                    var saved = repo.GetById <Counter>(model.Id);
                    saved.Label         = model.Label;
                    saved.CounterTypeId = model.CounterTypeId;
                    saved.Prefix        = model.Prefix;
                    saved.Suffix        = model.Suffix;
                    saved.InitValue     = model.InitValue;
                    saved.DigitCount    = model.DigitCount;
                    saved.ResetTypeId   = model.ResetTypeId;

                    repo.DeleteRange <CounterDocument>(x => x.CounterId == model.Id);
                    repo.DeleteRange <CounterCase>(x => x.CounterId == model.Id);
                    repo.DeleteRange <CounterSessionAct>(x => x.CounterId == model.Id);

                    switch (model.CounterTypeId)
                    {
                    case NomenclatureConstants.CounterTypes.Document:
                        saved.CounterDocument = new List <CounterDocument>()
                        {
                            new CounterDocument()
                            {
                                DocumentDirectionId = model.DocumentDirectionId
                            }
                        };
                        break;

                    case NomenclatureConstants.CounterTypes.Case:
                        saved.CounterCase = new List <CounterCase>()
                        {
                            new CounterCase()
                            {
                                CaseGroupId = model.CaseGroupId
                            }
                        };
                        break;

                    case NomenclatureConstants.CounterTypes.SessionAct:
                        saved.CounterSessionAct = new List <CounterSessionAct>()
                        {
                            new CounterSessionAct()
                            {
                                SessionActGroupId = model.SessionActGroupId
                            }
                        };
                        break;
                    }

                    repo.Update(saved);
                    repo.SaveChanges();
                }
                else
                {
                    switch (model.CounterTypeId)
                    {
                    case NomenclatureConstants.CounterTypes.Document:
                        model.CounterDocument = new List <CounterDocument>()
                        {
                            new CounterDocument()
                            {
                                DocumentDirectionId = model.DocumentDirectionId
                            }
                        };
                        break;

                    case NomenclatureConstants.CounterTypes.Case:
                        model.CounterCase = new List <CounterCase>()
                        {
                            new CounterCase()
                            {
                                CaseGroupId = model.CaseGroupId
                            }
                        };
                        break;

                    case NomenclatureConstants.CounterTypes.SessionAct:
                        model.CounterSessionAct = new List <CounterSessionAct>()
                        {
                            new CounterSessionAct()
                            {
                                SessionActGroupId = model.SessionActGroupId
                            }
                        };
                        break;
                    }

                    //Insert
                    repo.Add <Counter>(model);
                    repo.SaveChanges();
                }
                return(true);
            }
            catch (Exception ex)
            {
                logger.LogError(ex, $"Грешка при запис на Counter Id={ model.Id }");
                return(false);
            }
        }