예제 #1
0
        public UserInformationVM Login(string userName, string password)
        {
            var passWord = new VNPTCrypto().Encrypt(password);
            var listuser = this.Repository.GetQuery <AD_USER>()
                           .Where(r => r.DelFlg != true &&
                                  r.UserName.Equals(userName)).ToList();
            var user = new AD_USER();

            if (listuser.Count < 1)
            {
                return(new UserInformationVM()
                {
                    Msg = VNPTResources.ID.MsgLoginFail
                });
            }
            else
            {
                for (int i = 0; i < listuser.Count; i++)
                {
                    if (listuser[i].UserName.Equals(userName) && listuser[i].Password.Equals(passWord))
                    {
                        user = listuser[i];
                    }
                }
            }

            if (user.UserName is null)
            {
                return(new UserInformationVM()
                {
                    Msg = VNPTResources.ID.MsgLoginFail
                });
            }

            if (user.LockFlg.GetValueOrDefault())
            {
                return(new UserInformationVM()
                {
                    Msg = VNPTResources.ID.MsgUserLock
                });
            }

            var role = this.Repository.GetQuery <AD_ROLE>()
                       .FirstOrDefault(r => r.ID.Equals(user.RoleID));


            return(new UserInformationVM()
            {
                UserName = userName,
                FullName = string.IsNullOrEmpty(user.FullName) ? string.Empty : user.FullName,
                RoleID = role != null ? role.ID : string.Empty,
                RoleName = role != null ? role.Name : string.Empty
            });
        }
예제 #2
0
        private string validateUpdateUser(AD_USER dataRequest)
        {
            var errorMsg = "";

            //USERNAME
            if (string.IsNullOrEmpty(dataRequest.UserName))
            {
                errorMsg = string.Concat(errorMsg, string.Format(VNPTResources.Instance.Get(
                                                                     VNPTResources.ID.MsgErrorRequire), VNPTResources.Instance.Get(VNPTResources.ID.User_UserName)), ". ");
            }
            else
            {
                if (!CustomValidation.maxLength(50, dataRequest.UserName))
                {
                    errorMsg = string.Concat(errorMsg, string.Format(VNPTResources.Instance.Get(
                                                                         VNPTResources.ID.MsgErrorMaximumLength), VNPTResources.Instance.Get(VNPTResources.ID.User_UserName), 50), ". ");
                }
                if (CustomValidation.hasSpace(dataRequest.UserName))
                {
                    errorMsg = string.Concat(errorMsg, string.Format(VNPTResources.Instance.Get(
                                                                         VNPTResources.ID.MsgErrorHasSpace), VNPTResources.Instance.Get(VNPTResources.ID.User_UserName)), ". ");
                }
            }

            //PASSWORD
            if (string.IsNullOrEmpty(dataRequest.Password))
            {
                errorMsg = string.Concat(errorMsg, string.Format(VNPTResources.Instance.Get(
                                                                     VNPTResources.ID.MsgErrorRequire), VNPTResources.Instance.Get(VNPTResources.ID.User_Password)), ". ");
            }
            else
            {
                if (!CustomValidation.maxLength(150, dataRequest.Password))
                {
                    errorMsg = string.Concat(errorMsg, string.Format(VNPTResources.Instance.Get(
                                                                         VNPTResources.ID.MsgErrorMaximumLength), VNPTResources.Instance.Get(VNPTResources.ID.User_Password), 250), ". ");
                }
                if (CustomValidation.hasSpace(dataRequest.Password))
                {
                    errorMsg = string.Concat(errorMsg, string.Format(VNPTResources.Instance.Get(
                                                                         VNPTResources.ID.MsgErrorHasSpace), VNPTResources.Instance.Get(VNPTResources.ID.User_Password)), ". ");
                }
            }

            //FULLNAME
            if (string.IsNullOrEmpty(dataRequest.FullName))
            {
                errorMsg = string.Concat(errorMsg, string.Format(VNPTResources.Instance.Get(
                                                                     VNPTResources.ID.MsgErrorRequire), VNPTResources.Instance.Get(VNPTResources.ID.User_FullName)), ". ");
            }
            else
            {
                if (!CustomValidation.maxLength(250, dataRequest.FullName))
                {
                    errorMsg = string.Concat(errorMsg, string.Format(VNPTResources.Instance.Get(
                                                                         VNPTResources.ID.MsgErrorMaximumLength), VNPTResources.Instance.Get(VNPTResources.ID.User_FullName), 250), ". ");
                }
            }

            //PHONE
            if (string.IsNullOrEmpty(dataRequest.Phone))
            {
                //errorMsg = string.Concat(errorMsg, string.Format(VNPTResources.Instance.Get(
                //VNPTResources.ID.MsgErrorRequire), VNPTResources.Instance.Get(VNPTResources.ID.User_Phone)), ". ");
            }
            else
            {
                if (!CustomValidation.maxLength(50, dataRequest.Phone))
                {
                    //errorMsg = string.Concat(errorMsg, string.Format(VNPTResources.Instance.Get(
                    //   VNPTResources.ID.MsgErrorMaximumLength), VNPTResources.Instance.Get(VNPTResources.ID.User_Phone), 50), ". ");
                }
                if (this.Repository.GetQuery <AD_USER>().Any(r => r.Phone.Equals(dataRequest.Phone)) == true)
                {
                    //errorMsg = string.Concat(errorMsg, string.Format(VNPTResources.Instance.Get(
                    //    VNPTResources.ID.MsgErrorIsExists), VNPTResources.Instance.Get(VNPTResources.ID.User_Phone)), ". ");
                }
            }

            //DES
            if (!string.IsNullOrEmpty(dataRequest.Description))
            {
                if (!CustomValidation.maxLength(300, dataRequest.Description))
                {
                    errorMsg = string.Concat(errorMsg, string.Format(VNPTResources.Instance.Get(
                                                                         VNPTResources.ID.MsgErrorMaximumLength), VNPTResources.Instance.Get(VNPTResources.ID.User_Description), 300), ". ");
                }
            }

            //ROLE
            if (string.IsNullOrEmpty(dataRequest.RoleID))
            {
                errorMsg = string.Concat(errorMsg, string.Format(VNPTResources.Instance.Get(
                                                                     VNPTResources.ID.MsgErrorRequire), VNPTResources.Instance.Get(VNPTResources.ID.User_RoleID)), ". ");
            }
            else
            {
                if (this.Repository.GetQuery <AD_ROLE>().Any(r => r.ID.Equals(dataRequest.RoleID)) != true)
                {
                    errorMsg = string.Concat(errorMsg, string.Format(VNPTResources.Instance.Get(
                                                                         VNPTResources.ID.MsgErrorIDIsNotExists), VNPTResources.Instance.Get(VNPTResources.ID.User_RoleID)), ". ");
                }
                if (!CustomValidation.maxLength(50, dataRequest.RoleID))
                {
                    errorMsg = string.Concat(errorMsg, string.Format(VNPTResources.Instance.Get(
                                                                         VNPTResources.ID.MsgErrorMaximumLength), VNPTResources.Instance.Get(VNPTResources.ID.User_RoleID), 50), ". ");
                }
            }

            //PART
            if (string.IsNullOrEmpty(dataRequest.PartID))
            {
                errorMsg = string.Concat(errorMsg, string.Format(VNPTResources.Instance.Get(
                                                                     VNPTResources.ID.MsgErrorRequire), VNPTResources.Instance.Get(VNPTResources.ID.User_PartID)), ". ");
            }
            else
            {
                if (this.Repository.GetQuery <M_PART>().Any(r => r.ID.Equals(dataRequest.PartID)) != true)
                {
                    errorMsg = string.Concat(errorMsg, string.Format(VNPTResources.Instance.Get(
                                                                         VNPTResources.ID.MsgErrorIDIsNotExists), VNPTResources.Instance.Get(VNPTResources.ID.User_PartID)), ". ");
                }
            }

            //UNIT
            if (string.IsNullOrEmpty(dataRequest.UnitID))
            {
                errorMsg = string.Concat(errorMsg, string.Format(VNPTResources.Instance.Get(
                                                                     VNPTResources.ID.MsgErrorRequire), VNPTResources.Instance.Get(VNPTResources.ID.User_UnitID)), ". ");
            }
            else
            {
                if (this.Repository.GetQuery <M_UNIT>().Any(r => r.ID.Equals(dataRequest.UnitID)) != true)
                {
                    errorMsg = string.Concat(errorMsg, string.Format(VNPTResources.Instance.Get(
                                                                         VNPTResources.ID.MsgErrorIDIsNotExists), VNPTResources.Instance.Get(VNPTResources.ID.User_UnitID)), ". ");
                }
            }

            return(errorMsg);
        }
예제 #3
0
        public IHttpActionResult Saves(IEnumerable <AD_USER> dataRequest)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    var    model = ModelState;
                    string msg   = VNPTResources.Instance.Get(model);

                    return(Json(new TResult()
                    {
                        Status = (short)EStatus.Fail,
                        Msg = msg
                    }));
                }

                AD_USER dataItem = null;
                foreach (AD_USER item in dataRequest)
                {
                    var errorMsg = "";
                    errorMsg = this.validateAddUser(item);
                    if (!string.IsNullOrEmpty(errorMsg))
                    {
                        return(Json(new TResult()
                        {
                            Status = (short)EStatus.Fail,
                            Msg = errorMsg
                        }));
                    }

                    dataItem = this.Repository.GetQuery <AD_USER>().FirstOrDefault(r => r.UserName.Equals(item.UserName));
                    if (dataItem is null)
                    {
                        dataItem          = item.Clone();
                        dataItem.CreateAt = (dataItem.CreateAt != Constants.WO_VALUE_DETECT_INPUT_BLANK_DATE && dataItem.CreateAt != null) ? dataItem.CreateAt : DateTime.Now;
                        dataItem.UpdateAt = (dataItem.UpdateAt != Constants.WO_VALUE_DETECT_INPUT_BLANK_DATE && dataItem.UpdateAt != null) ? dataItem.UpdateAt : DateTime.Now;
                        if (!string.IsNullOrEmpty(item.Password))
                        {
                            dataItem.Password = (new VNPTCrypto()).Encrypt(item.Password);
                        }

                        this.Repository.Add(dataItem);
                        this.VNPTLogs.Write(this.Repository, EAction.Insert, JsonConvert.SerializeObject(dataItem));
                    }
                    else
                    {
                        return(Json(new TResult()
                        {
                            Status = (short)EStatus.Fail,
                            Msg = string.Format(VNPTResources.Instance.Get(VNPTResources.ID.MsgErrorIsExists), item.UserName)
                        }));
                    }
                }

                this.Repository.UnitOfWork.SaveChanges();

                return(Json(new TResult()
                {
                    Status = (short)EStatus.Ok,
                    Msg = VNPTResources.Instance.Get(VNPTResources.ID.MsgSaveOk),
                }));
            }
            catch (Exception e)
            {
                this.VNPTLogs.Write(this.Repository, e.Message);
                return(Json(new TResult()
                {
                    Status = (short)EStatus.Fail,
                    Msg = e.Message
                }));
            }
        }
예제 #4
0
        public IHttpActionResult Post([FromBody] AD_USER dataRequest)
        {
            try
            {
                //validate custom data input
                string errorMsg = null;
                errorMsg = this.validateAddUser(dataRequest);

                //validate custom data input
                if (errorMsg != "" && errorMsg != null)
                {
                    return(Json(new TResult()
                    {
                        Status = (short)EStatus.Fail,
                        Msg = errorMsg
                    }));
                }

                if (!ModelState.IsValid)
                {
                    var    model = ModelState;
                    string msg   = VNPTResources.Instance.Get(model);

                    return(Json(new TResult()
                    {
                        Status = (short)EStatus.Fail,
                        Msg = msg
                    }));
                }

                if (this.Repository.GetQuery <AD_USER>().Any(r => r.UserName.Equals(dataRequest.UserName)))
                {
                    return(Json(new TResult()
                    {
                        Status = (short)EStatus.Fail,
                        Msg = string.Format(VNPTResources.Instance.Get(VNPTResources.ID.MsgErrorIsExists), dataRequest.UserName)
                    }));
                }

                var dataItem = dataRequest.Clone();
                dataItem.CreateAt = DateTime.Now;
                dataItem.UpdateAt = DateTime.Now;

                if (!string.IsNullOrEmpty(dataRequest.Password))
                {
                    dataItem.Password = (new VNPTCrypto()).Encrypt(dataRequest.Password);
                }

                this.Repository.Add(dataItem);
                this.VNPTLogs.Write(this.Repository, EAction.Insert, JsonConvert.SerializeObject(dataItem));
                this.Repository.UnitOfWork.SaveChanges();

                return(Json(new TResult()
                {
                    Status = (short)EStatus.Ok,
                    Msg = VNPTResources.Instance.Get(VNPTResources.ID.MsgSaveOk),
                    Data = dataItem
                }));
            }
            catch (Exception e)
            {
                this.VNPTLogs.Write(this.RepositoryLog, e.Message);
                return(Json(new TResult()
                {
                    Status = (short)EStatus.Fail,
                    Msg = e.Message
                }));
            }
        }
예제 #5
0
        public IHttpActionResult ChangePassword(string newpassword, [FromBody] AD_USER dataRequest)
        {
            try
            {
                var dataItem = this.Repository.GetQuery <AD_USER>().FirstOrDefault(r => r.UserName.Equals(dataRequest.UserName));
                if (dataItem is null)
                {
                    return(Json(new TResult()
                    {
                        Status = (short)EStatus.Fail,
                        Msg = VNPTResources.Instance.Get(VNPTResources.ID.MsgNotFound)
                    }));
                }

                if ((new VNPTCrypto()).Encrypt(dataRequest.Password) != dataItem.Password)
                {
                    return(Json(new TResult()
                    {
                        Status = (short)EStatus.Fail,
                        Msg = VNPTResources.Instance.Get(VNPTResources.ID.MsgErrorWrongOldPassword)
                    }));
                }
                dataItem.Password = newpassword;

                //validate custom data input
                string errorMsg = this.validateUpdateUser(dataItem);

                //validate custom data input
                if (errorMsg != "" && errorMsg != null)
                {
                    return(Json(new TResult()
                    {
                        Status = (short)EStatus.Fail,
                        Msg = errorMsg
                    }));
                }

                if (!ModelState.IsValid)
                {
                    var    model = ModelState;
                    string msg   = VNPTResources.Instance.Get(model);

                    return(Json(new TResult()
                    {
                        Status = (short)EStatus.Fail,
                        Msg = msg
                    }));
                }


                dataItem.UpdateAt = DateTime.Now;
                dataItem.Password = (new VNPTCrypto()).Encrypt(dataItem.Password);


                this.Repository.Update(dataItem);
                this.VNPTLogs.Write(this.Repository, EAction.Update, JsonConvert.SerializeObject(dataItem));
                this.Repository.UnitOfWork.SaveChanges();

                return(Json(new TResult()
                {
                    Status = (short)EStatus.Ok,
                    Msg = VNPTResources.Instance.Get(VNPTResources.ID.MsgSaveOk),
                    Data = dataItem
                }));
            }
            catch (Exception e)
            {
                this.VNPTLogs.Write(this.RepositoryLog, e.Message);
                return(Json(new TResult()
                {
                    Status = (short)EStatus.Fail,
                    Msg = e.Message
                }));
            }
        }