Beispiel #1
0
        public ActionResult CreateBSO(BSOCreateModel model)
        {
            long?BSO_Id = model.Id;

            if (model.TemporaryPolicyNumber == null)
            {
                model.FailMessages.Add(string.Format("Заполните поле: № БСО."));
                return(View("CreateBSO", model));
            }

            if (model.TemporaryPolicyNumberTo == null)
            { //если вводим 1 БСО
                try
                {
                    long start = Int64.Parse(model.TemporaryPolicyNumber);
                    model.TemporaryPolicyNumber = string.Format("{0,9:D9}", start);
                }
                catch
                {
                    model.FailMessages.Add(string.Format("Невалидный номер БСО '{0}'. Введите правильное числовое значение.", model.TemporaryPolicyNumber));
                    return(View(model));
                }

                BSO bso = bsoBusinessLogic.BSO_GetByNumber(model.TemporaryPolicyNumber);
                if (bso != null)
                {
                    model.FailMessages.Add(string.Format("Введенный номер БСО {0} - уже существует!", model.TemporaryPolicyNumber));
                    return(View(model));
                }
                else
                {
                    model.UserId = CurrentUser.Id;
                    bsoBusinessLogic.BSO_Save(model.GetBSOSaveData());
                    bso = bsoBusinessLogic.BSO_GetByNumber(model.TemporaryPolicyNumber);
                    return(RedirectToAction("BSOHistory", "BSO", new { id = bso.Id }));
                }
            }
            else
            {//если вводим диапазон БСО.
                //тут быдлокод надо переписать, чтоб не шло столько лишних запросов к базе
                try
                {
                    long start      = Int64.Parse(model.TemporaryPolicyNumber);
                    long end        = Int64.Parse(model.TemporaryPolicyNumberTo);
                    long countTrue  = 0;
                    long countFalse = 0;

                    for (long i = start; i <= end; ++i)
                    {
                        BSO bso = bsoBusinessLogic.BSO_GetByNumber(string.Format("{0,9:D9}", i));
                        if (bso != null)
                        {
                            countFalse++;
                        }
                        else
                        {
                            model.TemporaryPolicyNumber = string.Format("{0,9:D9}", i);
                            model.UserId = CurrentUser.Id;
                            bsoBusinessLogic.BSO_Save(model.GetBSOSaveData());
                            countTrue++;
                        }
                    }
                    model.GoodMessages.Add(string.Format("Из диапазона номеров: {0} - {1}", string.Format("{0,9:D9}", start), string.Format("{0,9:D9}", end)));
                    model.GoodMessages.Add(string.Format("добавлено новых: {0}", countTrue));
                    if (countFalse > 0)
                    {
                        model.GoodMessages.Add(string.Format("обнаружено уже существующих: {0}", countFalse));
                    }
                    return(View("CreateBSO", model));
                }
                catch
                {
                    model.FailMessages.Add(string.Format("Невалидный номер БСО: '{0}' или '{1}'. Введите правильные числовые значения.",
                                                         model.TemporaryPolicyNumber, model.TemporaryPolicyNumberTo));
                    return(View("CreateBSO", model));
                }
            }
        }
Beispiel #2
0
        public ActionResult CreateBSO()
        {
            BSOCreateModel model = new BSOCreateModel();

            return(PartialView(model));
        }