Exemplo n.º 1
0
        public JsonResult Update_Account(Admin_Account obj)
        {
            List <Admin_Account> Acc = Admin_Account.Query("Where Id=@0", obj.Id).ToList();

            try
            {
                if (Acc.Any())
                {
                    if (!string.IsNullOrEmpty(obj.PasswordHash))
                    {
                        Acc.FirstOrDefault().PasswordHash = WebsiteExtension.EncryptPassword(obj.PasswordHash);
                    }
                    Acc.FirstOrDefault().UserName     = obj.UserName;
                    Acc.FirstOrDefault().FullName     = obj.FullName;
                    Acc.FirstOrDefault().TypeId       = obj.TypeId;
                    Acc.FirstOrDefault().Mobile       = obj.Mobile;
                    Acc.FirstOrDefault().Email        = obj.Email;
                    Acc.FirstOrDefault().Address      = obj.Address;
                    Acc.SingleOrDefault().UpdatedDate = DateTime.Now;
                    Acc.FirstOrDefault().Save();
                }
            }
            catch (Exception ex)
            {
                return(Json(0));
            }
            return(Json(new { Result = 1, Records = Acc }));
        }
Exemplo n.º 2
0
        public JsonResult Change_Account_Active(Admin_Account obj)
        {
            List <Admin_Account> Acc = Admin_Account.Query("Where Id=@0", obj.Id).ToList();

            try
            {
                if (Acc.Count > 0)
                {
                    Acc.FirstOrDefault().Active = obj.Active;
                    Acc.FirstOrDefault().Save();
                }
            }
            catch
            {
                return(Json(0));
            }
            return(Json(new { Result = 1, Records = Acc }));
        }
Exemplo n.º 3
0
        public ActionResult Login(Admin_Account md)
        {
            var error = String.Empty;

            if (md.UserName != null || md.UserName != "")
            {
                var convertPass = WebsiteExtension.EncryptPassword(md.PasswordHash);
                try
                {
                    List <Admin_Account> CheckUser = Admin_Account.Query("Where UserName=@0 AND PasswordHash=@1 AND BranchId=@2 AND Status=1",
                                                                         md.UserName, convertPass, 1).ToList();

                    if (CheckUser.Count > 0 && CheckUser.Count < 2)
                    {
                        Session["UserID"]   = CheckUser.FirstOrDefault().Id.ToString();
                        Session["TypeId"]   = CheckUser.FirstOrDefault().TypeId.ToString();
                        Session["UserName"] = CheckUser.FirstOrDefault().UserName.ToString();
                        Session["BranchId"] = CheckUser.FirstOrDefault().BranchId.ToString();
                        Session.Timeout     = 120;
                        return(Redirect("/"));
                    }
                    else
                    {
                        return(Redirect("/Login/Login"));
                    }
                }
                catch (Exception ex)
                {
                    return(Redirect("/Login/Login"));
                }
            }
            else
            {
                return(Redirect("/Login/Login"));
            }
        }
Exemplo n.º 4
0
        public JsonResult Get_Account_List(DataModel obj)
        {
            string order        = string.Empty;
            int    totalRecords = int.MinValue;

            if (obj._od != null)
            {
                order = " Order By " + obj._od.FirstOrDefault().Key + " " + obj._od.FirstOrDefault().Value;
            }

            List <Admin_Account>        AccList_source = new List <Admin_Account>();
            List <Admin_Account_Config> AccList        = new List <Admin_Account_Config>();
            string msg = string.Empty;

            try
            {
                if (obj._c != null)
                {
                    string querystring = "";
                    foreach (var k in obj._c)
                    {
                        switch (k.Key)
                        {
                        case "DisplayName":
                            querystring += k.Value.ToString();
                            break;

                        default:
                            querystring += k.Key + "=" + k.Value.ToString();
                            break;
                        }
                        if (!k.Equals(obj._c.Last()))
                        {
                            querystring += " AND ";
                        }
                    }
                    AccList_source = Admin_Account.Query("Where Status=1 AND " + querystring + order + "").ToList();
                }
                else
                {
                    AccList_source = Admin_Account.Query("Where Status=1 " + order + "").ToList();
                }

                // Map du lieu sang Model khac
                var config = new MapperConfiguration(cfg =>
                {
                    cfg.CreateMap <Admin_Account, Admin_Account_Config>();
                });
                IMapper mapper = config.CreateMapper();
                AccList = mapper.Map <List <Admin_Account>, List <Admin_Account_Config> >(AccList_source);

                int pSize = obj._lm;
                totalRecords = AccList.Count();
                if (totalRecords > 1)
                {
                    AccList = AccList.Skip(obj._os).Take(pSize).ToList();
                }
            }
            catch (Exception ex)
            {
                msg = ex.ToString();
            }

            return(Json(new { Result = 1, TotalRecordCount = totalRecords, Records = AccList, Message = msg }, JsonRequestBehavior.AllowGet));
        }