Exemplo n.º 1
0
        public JsonResult AddNewUserApps()
        {
            string        _status = MyEnums.enumStatus.SUCCESS.ToString();
            int           result  = 0;
            UserAppsModel usrMdl  = new UserAppsModel();

            if (Request.Form["Id"] == "")
            {
                usrMdl.UserName    = Request.Form["UserName"].ToString();
                usrMdl.Password    = Request.Form["Password"].ToString();
                usrMdl.EmployeeId  = Convert.ToInt32(Request.Form["Employee"].ToString());
                usrMdl.IsExpired   = Convert.ToBoolean(Request.Form["IsExpired"].ToString());
                usrMdl.CreatedBy   = "SYSTEM";
                usrMdl.CreatedDate = DateTime.Now;
                result             = new UserMgmtBLL().ValidateBeforSave(usrMdl, out _status);
            }
            else
            {
                usrMdl.UserName     = Request.Form["UserName"].ToString();
                usrMdl.Id           = Convert.ToInt32(Request.Form["Id"].ToString());
                usrMdl.EmployeeId   = Convert.ToInt32(Request.Form["Employee"].ToString());
                usrMdl.IsExpired    = Convert.ToBoolean(Request.Form["IsExpired"].ToString());
                usrMdl.ModifiedBy   = "SYSTEM";
                usrMdl.ModifiedDate = DateTime.Now;
                result = new UserMgmtBLL().Update(usrMdl, out _status);
            }

            return(Json(new { Status = _status, Result = result }, JsonRequestBehavior.AllowGet));
        }
Exemplo n.º 2
0
        public JsonResult FindById(string id)
        {
            UserAppsModel mdl = new UserAppsModel();

            if (id != "")
            {
                mdl = new UserMgmtBLL().FindById(Convert.ToInt32(id));
            }

            return(Json(new { Id = mdl.Id, UserName = mdl.UserName, IsExpired = mdl.IsExpired, EmployeeId = mdl.EmployeeId }, JsonRequestBehavior.AllowGet));
        }
Exemplo n.º 3
0
 public static string GetUserNameLogon(UserAppsModel _user)
 {
     if (_user != null)
     {
         return(_user.UserName);
     }
     else
     {
         return(" ");
     }
 }
Exemplo n.º 4
0
 public static int GetEmployeeID(UserAppsModel _user)
 {
     if (_user != null)
     {
         return(new UserMgmtBLL().GetEmployeeIDByUserName(_user.UserName));
     }
     else
     {
         return(0);
     }
 }
Exemplo n.º 5
0
 public void map(tb_userApps ent, out UserAppsModel obj)
 {
     obj = new UserAppsModel();
     if (ent == null)
     {
         throw new Exception("source cannot be null");
     }
     obj.Id         = ent.Id;
     obj.UserName   = ent.UserName;
     obj.Password   = ent.Password;
     obj.IsExpired  = ent.IsExpired;
     obj.EmployeeId = ent.EmployeeId;
 }
Exemplo n.º 6
0
        public int Update(UserAppsModel model, out string errMsg)
        {
            StringBuilder sb     = new StringBuilder();
            int           errctr = 0;

            errMsg = MyEnums.enumStatus.SUCCESS.ToString();
            using (TDMDBEntities context = new TDMDBEntities())
            {
                try
                {
                    //cek is any same username

                    var _u = context.tb_userApps.SingleOrDefault(x => x.UserName == model.UserName);
                    if (_u != null)
                    {
                        if (model.Id != _u.Id)
                        {
                            sb.Append("User Name sudah terpakai, silahkan mengganti dengan yang lain");
                            errctr += 1;
                        }
                    }

                    if (errctr <= 0)
                    {
                        var detil = context.tb_userApps.FirstOrDefault(x => x.Id == model.Id);
                        if (detil != null && ValidateBeforeUpdate(model, out errMsg))
                        {
                            detil.UserName     = model.UserName;
                            detil.EmployeeId   = model.EmployeeId;
                            detil.IsExpired    = model.IsExpired;
                            detil.ModifiedBy   = model.ModifiedBy;
                            detil.ModifiedDate = model.ModifiedDate;

                            result_affected = context.SaveChanges();
                        }
                    }
                    else
                    {
                        errMsg = sb.ToString();
                    }
                }
                catch (Exception ex)
                {
                    errMsg = ex.Message;
                }
            }
            return(result_affected);
        }
Exemplo n.º 7
0
        public ActionResult Authenticate(FormCollection fc)
        {
            string        _userName = fc["UserName"];
            string        _password = fc["Password"];
            string        mesg      = string.Empty;
            UserAppsModel usr       = new UserAppsModel();

            if (_userName == "admin" && _password == "admin")
            {
                usr.UserName         = "******";
                usr.EmployeeId       = 999;
                usr.EmployeeName     = "super admin";
                usr.IsExpired        = false;
                Session["UserLogOn"] = usr;
                Session["UserProps"] = "admin;admin";
                FormsAuthentication.SetAuthCookie(usr.UserName, true);
                return(RedirectToAction("Index", "Home"));
            }
            else
            {
                usr = new UserMgmtBLL().Authenticate(_userName, _password, out mesg);
                if (mesg == string.Empty)
                {
                    if (usr.Id > 0)
                    {
                        Session["UserLogOn"] = usr;
                        Session["UserProps"] = usr.EmployeeName + ";" + Common.GetRoleAppsName(usr.Role);
                        FormsAuthentication.SetAuthCookie(usr.UserName, true);
                        return(RedirectToAction("Index", "Home"));
                    }
                    else
                    {
                        ViewBag.ErrMsg = "You are not recognized";
                        return(View("Login"));
                    }
                }
                else
                {
                    ViewBag.ErrMsg = mesg;
                    return(View("Login"));
                }
            }
        }
Exemplo n.º 8
0
        private bool ValidateBeforeUpdate(UserAppsModel usr, out string err)
        {
            bool isValid = true;

            err = string.Empty;
            StringBuilder sb = new StringBuilder();

            if (usr.UserName == string.Empty)
            {
                sb.Append("User Name tidak boleh kosong /n");
                isValid = false;
            }
            if (usr.EmployeeId == 0)
            {
                sb.Append("Employee ID tidak boleh kosong /n");
                isValid = false;
            }
            return(isValid);
        }
Exemplo n.º 9
0
        public UserAppsModel MapToModel(tb_userApps fromEntity)
        {
            if (fromEntity == null)
            {
                throw new Exception("Source Data cannot be null");
            }
            UserAppsModel model = new UserAppsModel();

            model.Id           = fromEntity.Id;
            model.UserName     = fromEntity.UserName;
            model.Password     = fromEntity.Password;
            model.IsExpired    = fromEntity.IsExpired;
            model.EmployeeId   = fromEntity.EmployeeId;
            model.CreatedBy    = fromEntity.CreatedBy;
            model.CreatedDate  = fromEntity.CreatedDate;
            model.ModifiedBy   = fromEntity.ModifiedBy;
            model.ModifiedDate = fromEntity.ModifiedDate;

            return(model);
        }
Exemplo n.º 10
0
        public UserAppsModel Authenticate(string username, string password, out string mesg)
        {
            UserAppsModel model = new UserAppsModel();

            mesg = string.Empty;
            using (TDMDBEntities context = new TDMDBEntities())
            {
                var _q = context.tb_userApps.SingleOrDefault(x => x.UserName == username);
                if (_q != null)
                {
                    if (password == new Common().Decrypt(_q.Password, TDM_KEY))
                    {
                        var qry = context.tb_userApps.Join(context.tb_employee, u => u.EmployeeId, e => e.EmpID, (u, e) => new { u, e }).Select(s => new
                        {
                            s.u.UserName,
                            s.u.Id,
                            s.u.EmployeeId,
                            s.e.EmpName,
                            s.e.RoleApps,
                        })
                                  .SingleOrDefault(x => x.UserName == username);

                        model.Id           = qry.Id;
                        model.UserName     = qry.UserName;
                        model.EmployeeId   = qry.EmployeeId;
                        model.EmployeeName = qry.EmpName;
                        model.Role         = (int)qry.RoleApps;
                    }
                    else
                    {
                        mesg = "Password Salah";
                    }
                }
                else
                {
                    mesg = "UserName tidak ditemukan";
                }
            }
            return(model);
        }
Exemplo n.º 11
0
        public int ValidateBeforSave(UserAppsModel usr, out string mesg)
        {
            int result_affected = 0;

            mesg = string.Empty;
            StringBuilder sb = new StringBuilder();

            if (usr.UserName == string.Empty)
            {
                sb.Append("User Name tidak boleh kosong /n");
            }
            if (usr.EmployeeId == 0)
            {
                sb.Append("Employee ID tidak boleh kosong /n");
            }
            if (usr.Password == string.Empty)
            {
                sb.Append("Password tidak boleh kosong /n");
            }
            //cek is any same username
            using (TDMDBEntities context = new TDMDBEntities())
            {
                var _u = context.tb_userApps.SingleOrDefault(x => x.UserName == usr.UserName);
                if (_u != null)
                {
                    sb.Append("User Name sudah terpakai, silahkan mengganti dengan yang lain");
                }
            }

            mesg = sb.ToString();
            if (mesg == string.Empty)
            {
                usr.Password = new Common().Encrypt(usr.Password, TDM_KEY);
                string sSql = "Insert INTO tb_UserApps (UserName, Password, IsExpired, EmployeeId, CreatedBy)"
                              + "VALUES (@UserName, @Password, @IsExpired, @EmployeeId, @CreatedBy)";
                result_affected = InsertOrUpdate <UserAppsModel>(sSql, usr);
            }

            return(result_affected);
        }
Exemplo n.º 12
0
        public UserAppsModel FindById(int Id)
        {
            UserAppsModel usr = new UserAppsModel();

            using (TDMDBEntities context = new TDMDBEntities())
            {
                try
                {
                    var q = context.tb_userApps.SingleOrDefault(x => x.Id == Id);
                    if (q != null)
                    {
                        usr = MapToModel(q);
                    }
                }
                catch (Exception ex)
                {
                    throw new Exception(ex.Message);
                }
            }

            return(usr);
        }