//public ValidationResult AddUser(SEC_User objUser, string action, out string status)
        //{
        //    userDataService.AddUser(objUser, action, out status);
        //    if (status.Length > 0)
        //    {
        //        return new ValidationResult(status, localizationService.GetResource(status));
        //    }
        //    return ValidationResult.Success;
        //}

        ValidationResult IUserService.AddUser(SEC_User objUser, string action, out string status)
        {
            userDataService.AddUser(objUser, action, out status);
            if (status.Length > 0)
            {
                return(new ValidationResult(status, localizationService.GetResource(status)));
            }
            return(ValidationResult.Success);
        }
Пример #2
0
        public async Task <dynamic> ChangePassword(string password, string oldPassword)
        {
            SEC_User objUser = new SEC_User();

            action               = "changePassword";
            objUser.SetBy        = UserID;
            objUser.UserID       = UserID;
            objUser.ModifiedBy   = UserID;
            objUser.UserName     = StringEncription.Encrypt(oldPassword.Trim(), true);
            objUser.UserPassword = StringEncription.Encrypt(password.Trim(), true);
            respStatus           = await Task.Run(() => _userService.AddUser(objUser, action, out outStatus));

            return(Json(new { Message = respStatus.Message, respStatus }, JsonRequestBehavior.AllowGet));
        }
        // GET: SEC_User/Details/5
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            SEC_User sEC_User = db.SEC_User.Find(id);

            if (sEC_User == null)
            {
                return(HttpNotFound());
            }
            return(View(sEC_User));
        }
Пример #4
0
        public async Task <dynamic> UpdateUser(SEC_User objUser)
        {
            if (ModelState.IsValid)
            {
                action               = "edit";
                objUser.SetBy        = UserID;
                objUser.ModifiedBy   = objUser.SetBy;
                objUser.UserPassword = StringEncription.Encrypt(objUser.UserPassword, true);
                respStatus           = await Task.Run(() => _userService.AddUser(objUser, action, out outStatus));

                // Error handling.
                return(Json(new { Message = respStatus.Message, respStatus }, JsonRequestBehavior.AllowGet));
            }
            else
            {
                respStatus = new ValidationResult("E404", _localizationService.GetResource("E404"));
            }
            return(Json(new { Message = respStatus.Message, respStatus }, JsonRequestBehavior.AllowGet));
        }
        public ActionResult DeleteConfirmed(int id)
        {
            SEC_User sEC_User = db.SEC_User.Find(id);

            try
            {
                List <SEC_UserPrivileges> sEC_UserPrivileges_List = db.SEC_UserPrivileges.Where(e => e.UserID == sEC_User.UserID).ToList();
                db.SEC_UserPrivileges.RemoveRange(sEC_UserPrivileges_List);
                db.SEC_User.Remove(sEC_User);
                db.Entry(sEC_User).State = EntityState.Modified;
                sEC_User.IsActive        = false;
                db.SaveChanges();
            }
            catch (Exception ex)
            {
                ModelState.AddModelError("", "You can not Delete this User.");
                //return RedirectToAction("Index");
                return(View(sEC_User));
            }
            return(RedirectToAction("Index"));
        }
        public string AddUser(SEC_User objUser, string action, out string errorNumber)
        {
            errorNumber = String.Empty;
            try
            {
                DatabaseProviderFactory factory = new DatabaseProviderFactory();
                SqlDatabase             db      = factory.CreateDefault() as SqlDatabase;
                using (DbCommand dbCommandWrapper = db.GetStoredProcCommand("SetUsers"))
                {
                    // Set parameters
                    db.AddInParameter(dbCommandWrapper, "@UserID", SqlDbType.NVarChar, objUser.UserID);
                    db.AddInParameter(dbCommandWrapper, "@OwnerLevelID", SqlDbType.NVarChar, objUser.OwnerLevelID == null?"":objUser.OwnerLevelID.Trim());
                    db.AddInParameter(dbCommandWrapper, "@OwnerID ", SqlDbType.NVarChar, objUser.OwnerID == null ? "" : objUser.OwnerID.Trim());
                    db.AddInParameter(dbCommandWrapper, "@EmployeeID", SqlDbType.NVarChar, objUser.EmployeeID == null ? "" : objUser.EmployeeID);
                    db.AddInParameter(dbCommandWrapper, "@UserFullName", SqlDbType.NVarChar, objUser.UserFullName);
                    db.AddInParameter(dbCommandWrapper, "@UserDesignation ", SqlDbType.NVarChar, objUser.UserDesignation);
                    db.AddInParameter(dbCommandWrapper, "@JobLocation", SqlDbType.NVarChar, objUser.JobLocation);
                    db.AddInParameter(dbCommandWrapper, "@UserNo", SqlDbType.NVarChar, objUser.UserNo);

                    db.AddInParameter(dbCommandWrapper, "@UserName", SqlDbType.NVarChar, objUser.UserName == null?"": objUser.UserName.Trim());
                    db.AddInParameter(dbCommandWrapper, "@UserPassword", SqlDbType.NVarChar, objUser.UserPassword.Trim());
                    db.AddInParameter(dbCommandWrapper, "@RoleID ", SqlDbType.NVarChar, objUser.RoleID == null ? "" : objUser.RoleID.Trim());
                    db.AddInParameter(dbCommandWrapper, "@PermissionLevel", SqlDbType.NVarChar, objUser.PermissionLevel);
                    db.AddInParameter(dbCommandWrapper, "@UserLevelID", SqlDbType.Int, objUser.UserLevelID == null ? 0 : Convert.ToInt32(objUser.UserLevelID));
                    db.AddInParameter(dbCommandWrapper, "@SupervisorLevel ", SqlDbType.Int, objUser.SupervisorLevel == null ? 0 : Convert.ToInt32(objUser.SupervisorLevel));
                    db.AddInParameter(dbCommandWrapper, "@AccessOwnerLevel", SqlDbType.NVarChar, DataValidation.TrimmedOrDefault(objUser.AccessOwnerLevel));
                    db.AddInParameter(dbCommandWrapper, "@AccessDataLevel", SqlDbType.Int, objUser.AccessDataLevel == null ? 0 : Convert.ToInt32(objUser.AccessDataLevel));

                    db.AddInParameter(dbCommandWrapper, "@DocClassification", SqlDbType.Int, objUser.DocClassification == null ? 0 : Convert.ToInt32(objUser.DocClassification));
                    db.AddInParameter(dbCommandWrapper, "@ClassificationLevel", SqlDbType.Int, objUser.ClassificationLevel == null ? 0 : Convert.ToInt32(objUser.ClassificationLevel));
                    db.AddInParameter(dbCommandWrapper, "@SecurityStatus ", SqlDbType.NVarChar, objUser.SecurityStatus == null ? "" : objUser.SecurityStatus.Trim());
                    db.AddInParameter(dbCommandWrapper, "@DateLimit", SqlDbType.DateTime, objUser.DateLimit);
                    db.AddInParameter(dbCommandWrapper, "@DefaultServer", SqlDbType.NVarChar, objUser.DefaultServer);
                    db.AddInParameter(dbCommandWrapper, "@IntMailAddress ", SqlDbType.NVarChar, objUser.IntMailAddress);
                    db.AddInParameter(dbCommandWrapper, "@IntmailStatus", SqlDbType.NVarChar, objUser.IntmailStatus);
                    db.AddInParameter(dbCommandWrapper, "@ExtMailAddress", SqlDbType.NVarChar, objUser.ExtMailAddress);
                    db.AddInParameter(dbCommandWrapper, "@ExtMailStatus", SqlDbType.NVarChar, objUser.ExtMailStatus);

                    db.AddInParameter(dbCommandWrapper, "@ContactNo", SqlDbType.NVarChar, objUser.ContactNo);
                    db.AddInParameter(dbCommandWrapper, "@MessageStatus", SqlDbType.NVarChar, objUser.MessageStatus == null?"": objUser.MessageStatus.Trim());

                    db.AddInParameter(dbCommandWrapper, "@UserPicture ", SqlDbType.NVarChar, objUser.UserPicture == null ? "/noimage.jpg" : objUser.UserPicture.Trim());
                    db.AddInParameter(dbCommandWrapper, "@Remarks", SqlDbType.NVarChar, objUser.Remarks);

                    db.AddInParameter(dbCommandWrapper, "@SetOn ", SqlDbType.DateTime, DateTime.Now);
                    db.AddInParameter(dbCommandWrapper, "@SetBy", SqlDbType.NVarChar, objUser.SetBy);
                    db.AddInParameter(dbCommandWrapper, "@ModifiedOn", SqlDbType.DateTime, DateTime.Now);
                    db.AddInParameter(dbCommandWrapper, "@ModifiedBy", SqlDbType.NVarChar, objUser.ModifiedBy);
                    db.AddInParameter(dbCommandWrapper, "@Action", SqlDbType.VarChar, action);
                    db.AddInParameter(dbCommandWrapper, "@Status", SqlDbType.Int, objUser.Status);
                    db.AddOutParameter(dbCommandWrapper, spStatusParam, SqlDbType.NVarChar, 10);
                    // Execute SP.
                    db.ExecuteNonQuery(dbCommandWrapper);
                    // Getting output parameters and setting response details.
                    if (!db.GetParameterValue(dbCommandWrapper, spStatusParam).IsNullOrZero())
                    {
                        // Get the error number, if error occurred.
                        errorNumber = db.GetParameterValue(dbCommandWrapper, spStatusParam).PrefixErrorCode();
                    }
                }
            }
            catch (Exception ex)
            {
                errorNumber = "E404"; // Log ex.Message  Insert Log Table
            }
            return(errorNumber);
        }