コード例 #1
0
        public ActionResult Register(RegisterModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View());
            }
            var result = new Models.CustomJsonResult();

            try
            {
                var userId = _userService.CreateUser(model.Username, model.Password, model.FullName);
                if (userId > 0)
                {
                    result.Result = userId;
                    _userService.MapRoleToUser(userId, new List <int> {
                        RoleEnum.User
                    });
                    result.Message = "Đăng ký thành công!";
                }
                else
                {
                    result.Result  = 0;
                    result.Message = "Đăng ký thất bại!";
                }
            }
            catch (Exception ex)
            {
                result.Message = ex.Message;
            }
            return(Json(result));
        }
コード例 #2
0
        public ActionResult Login(LoginModel model)
        {
            var result = new Models.CustomJsonResult();

            if (!ModelState.IsValid)
            {
                return(View());
            }

            try
            {
                var userId = _userService.Login(model.LoginUsername, model.LoginPassword);
                if (userId > 0)
                {
                    result.Result = userId;
                    Session[Constant.SessionUsername] = model.LoginUsername;
                }
                else
                {
                    result.Result  = 0;
                    result.Message = "Password is correct or account is not active, please contact administrator!";
                }
            }
            catch (Exception ex)
            {
                result.Message = ex.Message;
            }
            return(Json(result, JsonRequestBehavior.AllowGet));
        }
コード例 #3
0
        public ActionResult InsertUpdateCatelogy(tblCategory model)
        {
            var result = new Models.CustomJsonResult();

            try
            {
                if (model != null && !string.IsNullOrEmpty(model.CategoryName))
                {
                    if (model.id > 0)
                    {
                        result.Result  = _catelogyServices.UpdateCatelogy(model);
                        result.Message = int.Parse(result.Result.ToString()) > 0 ? "Update catelogy success!" : "Action had error, please try again!";
                    }
                    else
                    {
                        result.Result  = _catelogyServices.InsertCatelogy(model);
                        result.Message = int.Parse(result.Result.ToString()) > 0 ? "Create new catelogy success!" : "Action had error, please try again!";
                    }
                }
                else
                {
                    result.Result  = 0;
                    result.Message = "Action had error, please try again!";
                }
            }
            catch (Exception ex)
            { }
            return(Json(result, JsonRequestBehavior.AllowGet));
        }
コード例 #4
0
        public JsonResult UpdateReciever(tblRecipientsInfo model)
        {
            var result = new Models.CustomJsonResult();

            try
            {
                if (model.id > 0)
                {
                    result.Result = _storeService.UpdateReciever(model);
                    if (int.Parse(result.Result.ToString()) > 0)
                    {
                        result.Message = "Update reciver successly";
                    }
                }
                else
                {
                    result.Result = _storeService.InsertReciever(model);
                    if (int.Parse(result.Result.ToString()) > 0)
                    {
                        result.Message = "Create new reciver successly";
                    }
                }
                if (int.Parse(result.Result.ToString()) < 1)
                {
                    result.Message = "Has error, please try again!";
                }
            }
            catch (Exception ex)
            {
                result.Message = ex.Message;
            }
            return(Json(result, JsonRequestBehavior.AllowGet));
        }
コード例 #5
0
        public ActionResult ChangePassword(ChangePasswordModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View());
            }
            var result = new Models.CustomJsonResult();

            try
            {
                string username  = GetUserNameFromSession();
                var    checkUser = _userService.GetUserByUsername(username);
                if (checkUser != null && checkUser.Id > 0)
                {
                    var changeUer = _userService.ChangePass(checkUser.Id, model.CurrentPassword, model.Password);
                    if (changeUer)
                    {
                        result.Result  = checkUser.Id;
                        result.Message = "Thay đổi mật khẩu thành công!";
                    }
                    else
                    {
                        result.Result  = 0;
                        result.Message = "Thay đổi mật khẩu thất bại!";
                    }
                }
            }
            catch (Exception ex)
            {
                result.Message = ex.Message;
            }
            return(Json(result, JsonRequestBehavior.AllowGet));
        }
コード例 #6
0
        public ActionResult Login(LoginModel model)
        {
            var result = new Models.CustomJsonResult();

            if (!ModelState.IsValid)
            {
                return(View());
            }

            try
            {
                var userId = _userService.Login(model.LoginUsername, model.LoginPassword);
                if (userId > 0)
                {
                    result.Result = userId;
                    Session[Constant.SessionUsername] = model.LoginUsername;
                    Lib.Business.Models.DBContext.UsTransport.tblStoreAccount storeOfUser = _storeService.SelectStoreByUserName(model.LoginUsername);
                    Session[Constant.SessionStoreID] = storeOfUser.id;
                }
                else
                {
                    result.Result  = 0;
                    result.Message = "Tài khoản không đúng hoặc chưa được kích hoạt, vui lòng liên hệ với administrator!";
                }
            }
            catch (Exception ex)
            {
                result.Message = ex.Message;
            }
            return(Json(result, JsonRequestBehavior.AllowGet));
        }
コード例 #7
0
        public ActionResult InsertStore(tblStoreAccount storeModel)
        {
            var result = new Models.CustomJsonResult();

            try
            {
                result.Result = storeService.InsertStore(storeModel);
                if (int.Parse(result.Result.ToString()) > 0)
                {
                    long UserID = userService.CreateUser(storeModel.Email, storeModel.Password, storeModel.FullName);
                    if (UserID > 0)
                    {
                        roleService.UpdateRoleUser(UserID, 4);
                        result.Message = "Create new Store successly! Please wait for system checkin and active your store";
                    }
                }
                if (int.Parse(result.Result.ToString()) < 1)
                {
                    result.Message = "Has error, please try again!";
                }
            }
            catch (Exception ex)
            {
                result.Message = ex.Message;
            }
            return(Json(result, JsonRequestBehavior.AllowGet));
        }
コード例 #8
0
        public JsonResult AJXUpdateSender(tblSender model)
        {
            var result = new Models.CustomJsonResult();

            try
            {
                if (model.Id > 0)
                {
                    result.Result = _storeService.UpdateSender(model);
                    if (int.Parse(result.Result.ToString()) > 0)
                    {
                        result.Message = "Sender Updated Succesful";
                    }
                }
                else
                {
                    result.Result = _storeService.InsertSender(model);
                    if (int.Parse(result.Result.ToString()) > 0)
                    {
                        result.Message = "Order Created Succesful";
                    }
                }
                if (int.Parse(result.Result.ToString()) < 1)
                {
                    result.Message = "Action has error, please try again!";
                }
            }
            catch (Exception ex)
            {
                result.Message = ex.Message;
            }
            return(Json(result, JsonRequestBehavior.AllowGet));
        }
コード例 #9
0
        public ActionResult UpdateStore(StoreModel storeModel)
        {
            var result = new Models.CustomJsonResult();

            try
            {
                if (storeModel.StoreAccount.id > 0)
                {
                    result.Result = _storeService.UpdateStore(storeModel.StoreAccount);
                    if (int.Parse(result.Result.ToString()) > 0)
                    {
                        result.Message = "Update Store successly";
                        int roleID = Request.Form["RoleID"] != null?int.Parse(Request.Form["RoleID"].ToString()) : -1;

                        string  userName = Request.Form["hUserName"];
                        tblUser _item    = _userService.GetUserByUsername(userName);
                        //If user had ready => update role for this user else add new user and update role
                        if (_item != null)
                        {
                            roleService.UpdateRoleUser(_item.Id, roleID);
                            if (storeModel.StoreAccount.Status > 0)
                            {
                                _item.IsActive = true;
                                _userService.UpdateUser(_item);
                            }
                        }
                        //else
                        //{
                        //    long _addnewUserID = userService.CreateUser(storeModel.StoreAccount.Email, storeModel.StoreAccount.Password, storeModel.StoreAccount.FullName);
                        //}
                    }
                }
                else
                {
                    result.Result = _storeService.InsertStore(storeModel.StoreAccount);
                    if (int.Parse(result.Result.ToString()) > 0)
                    {
                        long UserID = _userService.CreateUser(storeModel.StoreAccount.Email, storeModel.StoreAccount.Password, storeModel.StoreAccount.FullName);
                        if (UserID > 0)
                        {
                            roleService.UpdateRoleUser(UserID, 4);
                            result.Message = "Create new Store successly";
                        }
                    }
                }
                if (int.Parse(result.Result.ToString()) < 1)
                {
                    result.Message = "Has error, please try again!";
                }
            }
            catch (Exception ex)
            {
                result.Message = ex.Message;
            }
            return(Json(result, JsonRequestBehavior.AllowGet));
        }
コード例 #10
0
        public ActionResult ChangePassword(ChangePasswordModel model)
        {
            var result = new Models.CustomJsonResult
            {
                Result  = 0,
                Message = "Thay đổi mật khẩu thất bại!"
            };

            try
            {
                string username = GetUserNameFromSession();
                long   userid   = 0;
                var    rs       = _userService.ChangePassUser(username, model.CurrentPassword, model.Password, out userid);
                switch (rs)
                {
                case (int)BSNC.StatusChangePass.Faile:
                    result.Result  = 0;
                    result.Message = "Change password fail!";
                    break;

                case (int)BSNC.StatusChangePass.WrongPassword:
                    result.Result  = 0;
                    result.Message = "Curent password is correct!";
                    break;

                case (int)BSNC.StatusChangePass.IsChange:
                    result.Result  = userid;
                    result.Message = "Change password succesful!";
                    break;

                default:
                    break;
                }
            }
            catch (Exception ex)
            {
                result.Message = ex.Message;
            }
            return(Json(result, JsonRequestBehavior.AllowGet));
        }
コード例 #11
0
        public ActionResult InsertProduct(ProductDTO model)
        {
            var result = new Models.CustomJsonResult();

            try
            {
                if (model != null)
                {
                    var productModel = model.Map <tblProduct>();
                    result.Result  = _productServices.InsertProduct(productModel);
                    result.Message = int.Parse(result.Result.ToString()) > 0 ? "Create new product success!" : "Action had error or barcode is exists, please try again!";
                }
                else
                {
                    result.Result  = 0;
                    result.Message = "Action had error, please try again!";
                }
            }
            catch (Exception ex)
            { }
            return(Json(result, JsonRequestBehavior.AllowGet));
        }
コード例 #12
0
        public ActionResult InsertStore(StoreModel storeModel)
        {
            var result = new Models.CustomJsonResult();

            try
            {
                string notencodepassword = storeModel.StoreAccount.Password;
                storeModel.StoreAccount.Password      = Utils.HashMD5(storeModel.StoreAccount.Password);
                storeModel.StoreAccount.AliasFullName = Libs.UnicodeToNoneMark(storeModel.StoreAccount.StoreName);
                result.Result = storeService.InsertStore(storeModel.StoreAccount);
                if (int.Parse(result.Result.ToString()) > 0)
                {
                    long UserID = userService.CreateUser(storeModel.StoreAccount.Email, notencodepassword, storeModel.StoreAccount.FullName, false);
                    if (UserID > 0)
                    {
                        roleService.UpdateRoleUser(UserID, RoleEnum.Store);
                        result.Message = "Create New Store Succeed";
                    }
                    else
                    {
                        result.Result = UserID;
                    }
                }

                if (int.Parse(result.Result.ToString()) == -1)
                {
                    result.Message = "This store account already exists on system";
                }
                else if (int.Parse(result.Result.ToString()) < 1)
                {
                    result.Message = "Has error, please try again!";
                }
            }
            catch (Exception ex)
            {
                result.Message = ex.Message;
            }
            return(Json(result, JsonRequestBehavior.AllowGet));
        }
コード例 #13
0
ファイル: UserController.cs プロジェクト: anh120991/usexpress
        public JsonResult AJXCreateUser(tblUser model)
        {
            var result = new Models.CustomJsonResult();

            model.IsActive = Request.Form["IsActive"].ToString().Equals("1") ? true : false;
            if (model.Id > 0)
            {
                result.Result = _userService.UpdateUser(model);
                if (int.Parse(result.Result.ToString()) > 0)
                {
                    result.Message = "Update user success!";
                    if (Request.Form["slRole"] != null)
                    {
                        _roleServices.UpdateRoleUser(long.Parse(result.Result.ToString()), int.Parse(Request.Form["slRole"]));
                    }
                }
            }
            else
            {
                result.Result = _userService.RegisUser(model);
                if (int.Parse(result.Result.ToString()) > 0)
                {
                    result.Message = "Create user success!";
                    if (Request.Form["slRole"] != null)
                    {
                        _roleServices.UpdateRoleUser(long.Parse(result.Result.ToString()), int.Parse(Request.Form["slRole"]));
                    }
                }
            }
            if (int.Parse(result.Result.ToString()) == -1)
            {
                result.Message = "This account already exists on system";
            }
            else if (int.Parse(result.Result.ToString()) < 1)
            {
                result.Message = "Had error, please try again!";
            }
            return(Json(result));
        }
コード例 #14
0
        public ActionResult UpdateStore(StoreModel storeModel)
        {
            var result = new Models.CustomJsonResult();

            try
            {
                string notencodepassword = storeModel.StoreAccount.Password;

                if (storeModel.StoreAccount.id > 0)
                {
                    storeModel.StoreAccount.AliasFullName = Libs.UnicodeToNoneMark(storeModel.StoreAccount.StoreName);
                    result.Result = _storeService.UpdateStore(storeModel.StoreAccount);
                    if (int.Parse(result.Result.ToString()) > 0)
                    {
                        result.Message = "Update Store successly";
                        string  userName = Request.Form["hUserName"];
                        tblUser _item    = _userService.GetUserByUsername(userName);
                        if (_item != null)
                        {
                            if (storeModel.StoreAccount.Status > 0)
                            {
                                _item.IsActive = true;
                                _userService.UpdateUser(_item);
                            }
                        }

                        //int roleID = Request.Form["RoleID"] != null ? int.Parse(Request.Form["RoleID"].ToString()) : -1;

                        //tblUser _item = _userService.GetUserByUsername(userName);
                        ////If user had ready => update role for this user else add new user and update role
                        //if (_item != null)
                        //{
                        //    roleService.UpdateRoleUser(_item.Id, roleID);
                        //    if (storeModel.StoreAccount.Status > 0)
                        //    {
                        //        _item.IsActive = true;
                        //        _userService.UpdateUser(_item);
                        //    }
                        //}
                        //else
                        //{
                        //    long _addnewUserID = userService.CreateUser(storeModel.StoreAccount.Email, storeModel.StoreAccount.Password, storeModel.StoreAccount.FullName);
                        //}
                    }
                }
                else
                {
                    int  userID          = -1;
                    bool isActiveAccount = false;
                    storeModel.StoreAccount.AliasFullName = Libs.UnicodeToNoneMark(storeModel.StoreAccount.StoreName);
                    storeModel.StoreAccount.Password      = Utils.HashMD5(storeModel.StoreAccount.Password);
                    if (int.TryParse(Session[Constant.SessionUserID].ToString(), out userID))
                    {
                        var lstRoleId = _userService.GetLstRoleIdByUserId(int.Parse(Session[Constant.SessionUserID].ToString()));
                        if (lstRoleId != null && lstRoleId.Any())
                        {
                            if (lstRoleId.Contains(RoleEnum.Admin))
                            {
                                storeModel.StoreAccount.Status = 1;
                                isActiveAccount = true;
                            }
                        }
                    }



                    result.Result = _storeService.InsertStore(storeModel.StoreAccount);
                    if (int.Parse(result.Result.ToString()) > 0)
                    {
                        long UserID = _userService.CreateUser(storeModel.StoreAccount.Email, notencodepassword, storeModel.StoreAccount.FullName, isActiveAccount);
                        if (UserID > 0)
                        {
                            roleService.UpdateRoleUser(UserID, RoleEnum.Store);
                            result.Message = "Create New Store Succeed";
                        }
                        else
                        {
                            result.Result = UserID;
                        }
                    }
                }

                if (int.Parse(result.Result.ToString()) == -1)
                {
                    result.Message = "This store account already exists on system";
                }
                else if (int.Parse(result.Result.ToString()) < 1)
                {
                    result.Message = "Has error, please try again!";
                }
            }
            catch (Exception ex)
            {
                result.Message = ex.Message;
            }
            return(Json(result, JsonRequestBehavior.AllowGet));
        }