コード例 #1
0
        private string GetOrSetCustomer(tblCardSubmit obj, HttpPostedFileBase FileUpload)
        {
            if (FileUpload != null)
            {
                var extension = Path.GetExtension(FileUpload.FileName) ?? "";
                var fileName  = Path.GetFileName(string.Format("{0}{1}", StringUtil.RemoveSpecialCharactersVn(FileUpload.FileName.Replace(extension, "")).GetNormalizeString(), extension));
                var url       = ConfigurationManager.AppSettings["FileUploadAvatar"];

                obj.CustomerAvatar = string.Format("{0}{1}", url, fileName);
            }
            var id = "";

            if (!string.IsNullOrWhiteSpace(obj.CustomerID))
            {
                var tblCus = _tblCustomerService.GetById(Guid.Parse(obj.CustomerID));
                if (tblCus != null)
                {
                    id = tblCus.CustomerID.ToString();
                    tblCus.CustomerCode    = obj.CustomerCode;
                    tblCus.CustomerName    = obj.CustomerName;
                    tblCus.CustomerGroupID = obj.CustomerGroupID;
                    tblCus.Address         = obj.CustomerAddress;
                    tblCus.Avatar          = obj.CustomerAvatar;
                    tblCus.IDNumber        = obj.CustomerIdentify;
                    tblCus.Mobile          = obj.CustomerMobile;
                    tblCus.CompartmentId   = obj.CompartmentId;
                    _tblCustomerService.Update(tblCus);
                }
                else
                {
                    tblCus = new tblCustomer()
                    {
                        CustomerID       = Guid.NewGuid(),
                        Address          = obj.CustomerAddress,
                        Avatar           = obj.CustomerAddress,
                        CustomerName     = obj.CustomerName,
                        CustomerGroupID  = obj.CustomerGroupID,
                        Description      = "",
                        Mobile           = obj.CustomerMobile,
                        IDNumber         = obj.CustomerIdentify,
                        AccessLevelID    = "",
                        CustomerCode     = obj.CustomerCode,
                        Finger1          = "",
                        Finger2          = "",
                        Inactive         = false,
                        SortOrder        = 0,
                        DevPass          = "",
                        CompartmentId    = obj.CompartmentId,
                        AccessExpireDate = Convert.ToDateTime("2099/12/31")
                    };
                    _tblCustomerService.Create(tblCus);
                }
            }
            else
            {
                if (!string.IsNullOrWhiteSpace(obj.CustomerCode))
                {
                    var tblCustomerByCode = _tblCustomerService.GetByCode(obj.CustomerCode);
                    if (tblCustomerByCode != null)
                    {
                        id = tblCustomerByCode.CustomerID.ToString();
                    }
                    else
                    {
                        var tbl = new tblCustomer()
                        {
                            CustomerID       = Guid.NewGuid(),
                            Address          = obj.CustomerAddress,
                            Avatar           = obj.CustomerAvatar,
                            CustomerName     = obj.CustomerName,
                            CustomerGroupID  = obj.CustomerGroupID,
                            Description      = "",
                            Mobile           = obj.CustomerMobile,
                            IDNumber         = obj.CustomerIdentify,
                            AccessLevelID    = "",
                            CustomerCode     = obj.CustomerCode,
                            Finger1          = "",
                            Finger2          = "",
                            Inactive         = false,
                            SortOrder        = 0,
                            DevPass          = "",
                            CompartmentId    = obj.CompartmentId,
                            AccessExpireDate = Convert.ToDateTime("2099/12/31")
                        };
                        var result = _tblCustomerService.Create(tbl);
                        if (result.isSuccess)
                        {
                            id = tbl.CustomerID.ToString();
                        }
                    }
                }
            }
            return(id);
        }
コード例 #2
0
        public ActionResult Create(tblCustomer obj, HttpPostedFileBase FileUpload, bool SaveAndCountinue = false, string key = "", string customergroup = "", string customerstatus = "", string RePassword = "", string hidFinger1 = "", string hidFinger2 = "")
        {
            ViewBag.keyValue            = key;
            ViewBag.CustomerGroupValue  = customergroup;
            ViewBag.customerstatusValue = customerstatus;

            ViewBag.CustomerGroups = GetMenuList();
            ViewBag.ControllerList = _tblAccessControllerService.GetAllActive();
            ViewBag.LevelList      = _tblAccessLevelService.GetAllActive();

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

            var existed = _tblCustomerService.GetByCode(obj.CustomerCode);

            if (existed != null)
            {
                ModelState.AddModelError("CustomerCode", "Mã khách hàng đã tồn tại");
                return(View(obj));
            }

            if (!string.IsNullOrWhiteSpace(obj.Password))
            {
                if (obj.Password != RePassword)
                {
                    ModelState.AddModelError("Password", "Vui lòng nhập lại đúng mật khẩu");
                    return(View(obj));
                }

                obj.Password = CryptorEngine.Encrypt(obj.Password, true);
            }

            if (!string.IsNullOrWhiteSpace(obj.DevPass))
            {
                var devpass = _tblCustomerService.GetByDevPass(obj.DevPass);
                if (devpass != null)
                {
                    ModelState.AddModelError("DevPass", "Mật khẩu đã tồn tại");
                    return(View(obj));
                }
            }

            //Gán giá trị
            obj.CustomerID       = Guid.NewGuid();
            obj.AccessExpireDate = Convert.ToDateTime("2099/12/31");
            obj.Finger1          = !string.IsNullOrWhiteSpace(hidFinger1) ? hidFinger1 : "";
            obj.Finger2          = !string.IsNullOrWhiteSpace(hidFinger2) ? hidFinger2 : "";
            obj.DevPass          = !string.IsNullOrEmpty(obj.DevPass) ? obj.DevPass : "";

            if (FileUpload != null)
            {
                var extension = Path.GetExtension(FileUpload.FileName) ?? "";
                var fileName  = Path.GetFileName(string.Format("{0}{1}", StringUtil.RemoveSpecialCharactersVn(FileUpload.FileName.Replace(extension, "")).GetNormalizeString(), extension));

                var url = ConfigurationManager.AppSettings["FileUploadAvatar"];
                obj.Avatar = string.Format("{0}{1}", url, fileName);
            }

            //Thực hiện thêm mới
            var result = _tblCustomerService.Create(obj);

            if (result.isSuccess)
            {
                WriteLog.Write(result, GetCurrentUser.GetUser(), obj.CustomerID.ToString(), obj.CustomerCode, "tblCustomer", ConstField.AccessControlCode, ActionConfigO.Create);

                UploadFile(FileUpload);

                if (SaveAndCountinue)
                {
                    TempData["Success"] = result.Message;
                    return(RedirectToAction("Create", new { key = key, customergroup = customergroup, customerstatus = customerstatus, selectedId = obj.CustomerID }));
                }

                return(RedirectToAction("Index", new { key = key, customergroup = customergroup, customerstatus = customerstatus, selectedId = obj.CustomerID }));
            }
            else
            {
                ModelState.AddModelError("", result.Message);
                return(View(obj));
            }
        }
コード例 #3
0
        public ActionResult Create(tblCustomer obj, HttpPostedFileBase FileUpload, bool SaveAndCountinue = false, string key = "", string customergroup = "", string customerstatus = "", string RePassword = "")
        {
            var DictionaryAction = FunctionHelper.GetLocalizeDictionary("Home", "notification");

            ViewBag.keyValue            = key;
            ViewBag.CustomerGroupValue  = customergroup;
            ViewBag.customerstatusValue = customerstatus;

            ViewBag.CustomerGroups = GetMenuList();
            var systemconfig = _tblSystemConfigService.GetDefault();

            ViewBag.IsCompartment = systemconfig != null ? systemconfig.isCompartment : true;
            //Kiểm tra
            if (!ModelState.IsValid)
            {
                return(View(obj));
            }

            if (string.IsNullOrWhiteSpace(obj.CustomerName))
            {
                ModelState.AddModelError("CustomerName", DictionaryAction["enter_customer_name"]);
                return(View(obj));
            }

            if (string.IsNullOrWhiteSpace(obj.CustomerCode))
            {
                ModelState.AddModelError("CustomerCode", DictionaryAction["enter_customer_code"]);
                return(View(obj));
            }

            var existed = _tblCustomerService.GetByCode(obj.CustomerCode);

            if (existed != null)
            {
                ModelState.AddModelError("CustomerCode", DictionaryAction["Customer_code_already_exists"]);
                return(View(obj));
            }

            if (!string.IsNullOrWhiteSpace(obj.Password))
            {
                if (obj.Password != RePassword)
                {
                    ModelState.AddModelError("Password", DictionaryAction["correct_password"]);
                    return(View(obj));
                }

                obj.Password = CryptorEngine.Encrypt(obj.Password, true);
            }

            //Gán giá trị
            obj.CustomerID       = Guid.NewGuid();
            obj.AccessLevelID    = "";
            obj.Finger1          = "";
            obj.Finger2          = "";
            obj.DevPass          = "";
            obj.AccessExpireDate = Convert.ToDateTime("2099/12/31");
            obj.CompartmentId    = !string.IsNullOrEmpty(obj.CompartmentId) ? obj.CompartmentId.Trim() : "";
            if (FileUpload != null)
            {
                var extension = Path.GetExtension(FileUpload.FileName) ?? "";
                var fileName  = Path.GetFileName(string.Format("{0}{1}", StringUtil.RemoveSpecialCharactersVn(FileUpload.FileName.Replace(extension, "")).GetNormalizeString(), extension));

                var url = ConfigurationManager.AppSettings["FileUploadAvatar"];
                obj.Avatar = string.Format("{0}{1}", url, fileName);
            }

            if (!string.IsNullOrEmpty(obj.Address))
            {
                obj.AddressUnsign = StringUtil.RemoveSpecialCharactersVn(obj.Address.ToLower()).Replace("-", " ");
            }

            //Thực hiện thêm mới
            var result = _tblCustomerService.Create(obj);

            if (result.isSuccess)
            {
                WriteLog.Write(result, GetCurrentUser.GetUser(), obj.CustomerID.ToString(), obj.CustomerCode, "tblCustomer", ConstField.ParkingCode, ActionConfigO.Create);

                UploadFile(FileUpload);

                if (SaveAndCountinue)
                {
                    TempData["Success"] = result.Message;
                    return(RedirectToAction("Create", new { key = key, customergroup = customergroup, customerstatus = customerstatus, selectedId = obj.CustomerID }));
                }

                return(RedirectToAction("Index", new { key = key, customergroup = customergroup, customerstatus = customerstatus, selectedId = obj.CustomerID }));
            }
            else
            {
                ModelState.AddModelError("", result.Message);
                return(View(obj));
            }
        }