// GET: Admin
        public ActionResult Index()
        {
            string UserName = Request["username"];
            string Password = Request["password"];

            Constants.LoginResult result;
            BO_Users user        = new BO_Users();
            BO_Users currentUser = BL_Users.Login(Session, UserName, Password, out result);

            if (UserName != null && Password != null)
            {
                if (result == Constants.LoginResult.Success)
                {
                    Session[Constants.SESSION_USERKEY] = currentUser;
                    return(Redirect("/Sales/Index"));
                }
                else
                {
                    ViewBag.Validation = "Invalid";
                }
            }



            return(View());
        }
        public static BO_Users Login(HttpSessionStateBase session, string UserName, string Password, out Constants.LoginResult result)
        {
            using (AprosysAccountingEntities db = new AprosysAccountingEntities())
            {
                BO_Users user = new BO_Users();

                var obj = db.Users.Where(x => x.UserName == UserName && x.Password == Password && x.IsActive == true).FirstOrDefault();
                if (obj != null)
                {
                    result         = Constants.LoginResult.Success;
                    user.firstName = obj.FirstName;
                    user.lastName  = obj.LastName;
                    user.id        = obj.Id;
                    user.phone     = obj.Phone;
                    user.userId    = obj.UserName;
                    // user.adminRights = obj.AdminRights??false;
                }
                else
                {
                    result = Constants.LoginResult.WrongPwd;
                }

                return(user);
            }
        }
        public static string SaveUser(BO_Users _user, int UserID)
        {
            using (AprosysAccountingEntities db = new AprosysAccountingEntities())
            {
                try
                {
                    //var objcheck = db.Users.Where(x => x.UserName.ToLower() == _user.userId.ToLower()).FirstOrDefault();
                    //if (objcheck != null)
                    //{
                    //    return "User Already Exists";
                    //}

                    var obj = _user.id == 0 ? new ApprosysAccDB.User() : db.Users.Where(x => x.Id == _user.id).FirstOrDefault();
                    if (_user.id > 0)
                    {
                        var checkCust = db.Users.Where(x => x.UserName.ToLower() == _user.userId.ToLower() && x.Id != _user.id && x.IsActive == true).FirstOrDefault();
                        if (checkCust != null)
                        {
                            return("UserID Already Exists");
                        }
                    }
                    if (obj != null && obj.Id > 0)
                    {
                        obj.ModifiedBy = UserID;
                        obj.ModifiedOn = BL_Common.GetDatetime();
                    }
                    obj.Id = _user.id;

                    obj.LastName  = _user.lastName ?? "";
                    obj.FirstName = _user.firstName ?? "";
                    obj.UserName  = _user.userId;
                    obj.Password  = _user.password;
                    obj.Phone     = _user.phone;
                    obj.Email     = _user.email;
                    obj.IsActive  = true;
                    obj.Address   = _user.address;


                    obj.IsActive    = true;
                    obj.AdminRights = _user.adminRights;
                    if (obj.Id == 0)
                    {
                        obj.CreatedBy = UserID;
                        obj.CreatedOn = BL_Common.GetDatetime();
                        var objcheck = db.Users.Where(x => x.UserName.ToLower() == _user.userId.ToLower() && x.Id != _user.id && x.IsActive == true).FirstOrDefault();
                        if (objcheck != null)
                        {
                            return("UserID Already Exists");
                        }
                        db.Users.Add(obj);
                    }

                    db.SaveChanges();
                    return("success");

                    // return "Insertion Failed";
                }
                catch { throw; }
            }
        }
        protected override void Initialize(RequestContext requestContext)
        {
            UserAprosysAccounting = requestContext.HttpContext.Session[BussinessLogics.Constants.SESSION_USERKEY] as BO_Users;
            RequestGUID           = Guid.NewGuid().ToString();
            string IP = requestContext.HttpContext.Request.UserHostAddress;

            //if (!AllowedIPs.Contains(IP) && !requestContext.HttpContext.Request.IsLocal)
            //{
            //    UserRSRS = null;
            //}

            try
            {
                string sessionID = "NULL";
                if (requestContext.HttpContext.Session != null)
                {
                    sessionID = requestContext.HttpContext.Session.SessionID;
                }
                string LogMessage = "RequestGUID is " + RequestGUID + " IP is " + requestContext.HttpContext.Request.UserHostAddress + ",  UserID = " + UserAprosysAccounting.id + ", UserName="******" , SessionID is " + sessionID + " Url is " + requestContext.HttpContext.Request.RawUrl + " PostData is" + requestContext.HttpContext.Request.Form.ToString();
                Logger.Write("RequestLog", LogMessage, "", Logger.LogType.InformationLog);
            }
            catch
            {
            }
            if (UserAprosysAccounting == null)
            {
                string    _actionName = requestContext.RouteData.Values["action"].ToString();
                UrlHelper Url         = new UrlHelper(requestContext);
                if (_actionName == "Index" ||
                    _actionName == "Beta" //We Have to remove this consdition when we change Name of Home/Beta to Home/Index
                    )
                {
                    var currenturl = requestContext.HttpContext.Request.Url.AbsoluteUri;
                    requestContext.HttpContext.Response.Clear();
                    requestContext.HttpContext.Response.Redirect(Url.Action("Logout", "Admin", new { redirecturl = currenturl }));
                    requestContext.HttpContext.Response.End();
                }
                else
                {
                    //For Ajax Call's
                    requestContext.HttpContext.Response.Clear();
                    requestContext.HttpContext.Response.Redirect(Url.Action("GetSessionExpiredCode", "Admin"));
                    requestContext.HttpContext.Response.End();
                }
            }
            else
            {
                base.Initialize(requestContext);
            }
        }
Beispiel #5
0
        public static BO_Users GetUserDetail(int UserID)
        {
            using (AprosysAccountingEntities db = new AprosysAccountingEntities())
            {
                BO_Users user = new BO_Users();
                var      obj  = db.Users.Where(x => x.Id == UserID && x.IsActive == true).FirstOrDefault();
                if (obj != null)
                {
                    user.address     = obj.Address;
                    user.email       = obj.Email;
                    user.firstName   = obj.FirstName;
                    user.lastName    = obj.LastName;
                    user.id          = obj.Id;
                    user.userId      = obj.UserName;
                    user.adminRights = obj.AdminRights ?? false;
                }

                return(user);
            }
        }