예제 #1
0
        public ActionResult Create(tblCardGroup obj, bool SaveAndCountinue = false)
        {
            //Danh sách sử dụng
            ViewBag.Url = url;

            //Kiểm tra
            if (!ModelState.IsValid)
            {
                return(View(obj));
            }

            if (string.IsNullOrEmpty(obj.CardGroupName))
            {
                ModelState.AddModelError("CardGroupName", "Vui lòng nhập tên nhóm thẻ");
                return(View(obj));
            }

            var cgroup = _tblCardGroupService.GetByName(obj.CardGroupName);

            if (cgroup != null)
            {
                ModelState.AddModelError("CardGroupName", "Nhóm thẻ đã tồn tại");
                return(View(obj));
            }

            //Gán giá trị
            obj.CardGroupID = Guid.NewGuid();
            obj.DayTimeFrom = "";
            obj.DayTimeTo   = "";
            obj.TimePeriods = "";
            obj.Costs       = "";
            //Thực hiện thêm mới
            var result = _tblCardGroupService.Create(obj);

            if (result.isSuccess)
            {
                WriteLog.Write(result, GetCurrentUser.GetUser(), obj.CardGroupID.ToString(), obj.CardGroupName, "tblCardGroup", ConstField.AccessControlCode, ActionConfigO.Create);

                if (SaveAndCountinue)
                {
                    TempData["Success"] = result.Message;
                    return(RedirectToAction("Create"));
                }

                if (!string.IsNullOrEmpty(url))
                {
                    return(Redirect(url));
                }
                else
                {
                    return(RedirectToAction("Index"));
                }
            }
            else
            {
                ModelState.AddModelError("", result.Message);
                return(View(obj));
            }
        }
예제 #2
0
        public ActionResult Create(tblCardGroup obj, string listLanes = "", string selectValueBlockTime = "", string txtEachFee = "", bool SaveAndCountinue = false)
        {
            var DictionaryAction = FunctionHelper.GetLocalizeDictionary("Home", "notification");

            //Danh sách sử dụng
            ViewBag.CardTypes     = GetCardType();
            ViewBag.VehicleGroups = GetVehicleGroup();
            ViewBag.Formulation   = GetFormulation();
            ViewBag.Url           = url;

            //Kiểm tra
            if (!ModelState.IsValid)
            {
                return(View(obj));
            }

            if (string.IsNullOrEmpty(obj.CardGroupName))
            {
                ModelState.AddModelError("CardGroupName", DictionaryAction["enter_CardGrp_name"]);
                return(View(obj));
            }

            if (string.IsNullOrEmpty(listLanes))
            {
                ModelState.AddModelError("LaneIDs", DictionaryAction["CardGrp_lane"]);
                return(View(obj));
            }


            var cgroup = _tblCardGroupService.GetByName(obj.CardGroupName);

            if (cgroup != null)
            {
                ModelState.AddModelError("CardGroupName", DictionaryAction["CardGrp_already_exists"]);
                return(View(obj));
            }

            //Gán giá trị
            obj.CardGroupID = Guid.NewGuid();
            obj.LaneIDs     = listLanes;

            if (!string.IsNullOrWhiteSpace(txtEachFee))
            {
                txtEachFee  = txtEachFee.Replace(".", "");
                obj.EachFee = Convert.ToInt32(txtEachFee);
            }

            if (string.IsNullOrEmpty(obj.TimePeriods))
            {
                obj.TimePeriods = "00:00-00:00-00:00";
            }

            if (string.IsNullOrEmpty(obj.Costs))
            {
                obj.Costs = "0";
            }

            #region Block and time
            if (!string.IsNullOrWhiteSpace(selectValueBlockTime))
            {
                var arr = selectValueBlockTime.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries);
                if (arr.Any())
                {
                    for (int i = 0; i < arr.Length; i++)
                    {
                        var objBT = arr[i].Split(new[] { '-' }, StringSplitOptions.RemoveEmptyEntries);

                        if (objBT.Any())
                        {
                            var block = !string.IsNullOrEmpty(objBT[0].ToString()) ? Convert.ToInt32(objBT[0].ToString().Replace(".", "")) : 0;
                            var time  = !string.IsNullOrEmpty(objBT[1].ToString()) ? Convert.ToInt32(objBT[1].ToString()) : 0;

                            switch (i)
                            {
                            case 0:
                                obj.Block0 = block;
                                obj.Time0  = time;
                                break;

                            case 1:
                                obj.Block1 = block;
                                obj.Time1  = time;
                                break;

                            case 2:
                                obj.Block2 = block;
                                obj.Time2  = time;
                                break;

                            case 3:
                                obj.Block3 = block;
                                obj.Time3  = time;
                                break;

                            case 4:
                                obj.Block4 = block;
                                obj.Time4  = time;
                                break;

                            case 5:
                                obj.Block5 = block;
                                obj.Time5  = time;
                                break;
                            }
                        }
                    }
                }
            }
            #endregion

            //Thực hiện thêm mới
            var result = _tblCardGroupService.Create(obj);
            if (result.isSuccess)
            {
                if (SaveAndCountinue)
                {
                    TempData["Success"] = result.Message;
                    return(RedirectToAction("Create"));
                }

                if (!string.IsNullOrEmpty(url))
                {
                    return(Redirect(url));
                }
                else
                {
                    return(RedirectToAction("Index"));
                }
            }
            else
            {
                ModelState.AddModelError("", result.Message);
                return(View(obj));
            }
        }