public JsonResult ActivateUser(string Userid)
        {
            int    result = 0;
            string msg    = string.Empty;
            //string orgid = Session["OrgId"].ToString();
            string orgid = User.OrgId;

            EPortal.Models.UserRole Userrole = null;
            EPortal.Models.UserInfo userinfo = null;
            using (EPortalEntities entity = new EPortalEntities())
            {
                Userrole = (from us in entity.UserRoles
                            where us.OrganizationID == orgid &&
                            us.UserId == Userid
                            select us).FirstOrDefault();
                userinfo = (from u in entity.UserInfoes
                            where u.OrganizationID == orgid &&
                            u.Id == Userid
                            select u).FirstOrDefault();
                if (userinfo != null)
                {
                    if (userinfo.NoOfLogin.HasValue && userinfo.NoOfLogin.Value == 1)
                    {
                        userinfo.NoOfLogin           = null;
                        entity.Entry(userinfo).State = System.Data.Entity.EntityState.Modified;
                    }
                }
                if (Userrole != null)
                {
                    Userrole.RowState = true;

                    entity.Entry(Userrole).State = System.Data.Entity.EntityState.Modified;
                    result = entity.SaveChanges();
                }
                else
                {
                    msg = "Please assign role for selected user.";
                }
            }

            return(Json(new { result = result > 0 ? true : false, msg = msg }, JsonRequestBehavior.AllowGet));
        }
        public JsonResult SaveSelectedRole(string selectedUser, string selectedrole)
        {
            //string orgid = Session["OrgId"].ToString();

            string orgid = User.OrgId;

            EPortal.Models.UserRole Userrorle = null;
            int result = 0;

            using (EPortalEntities entity = new EPortalEntities())
            {
                Userrorle = (from usr in entity.UserRoles
                             where usr.OrganizationID == orgid &&
                             usr.RoleId == selectedrole &&
                             usr.UserId == selectedUser
                             select usr).FirstOrDefault();
                if (Userrorle == null)
                {
                    Userrorle                     = new UserRole();
                    Userrorle.Id                  = Guid.NewGuid().ToString();
                    Userrorle.UserId              = selectedUser;
                    Userrorle.RoleId              = selectedrole;
                    Userrorle.OrganizationID      = orgid;
                    Userrorle.RowState            = false;
                    Userrorle.CreateDateTime      = System.DateTime.Now;
                    entity.Entry(Userrorle).State = System.Data.Entity.EntityState.Added;
                }
                else
                {
                    entity.Entry(Userrorle).State = System.Data.Entity.EntityState.Modified;
                }

                result = entity.SaveChanges();
            }
            return(Json(result > 0 ? true : false, JsonRequestBehavior.AllowGet));
        }
Esempio n. 3
0
        public ActionResult Login(EPortal.Models.UserInfo Userinfo)
        {
            if (Userinfo == null)
            {
                throw new ArgumentNullException(nameof(Userinfo));
            }

            JavaScriptSerializer serializer = new JavaScriptSerializer();

            EPortal.Models.Organization org      = null;
            EPortal.Models.UserInfo     Userdata = null;
            EPortal.Models.UserRole     Userrole = null;
            bool sendmailper = false;

            using (EPortalEntities entity = new EPortalEntities())
            {
                try
                {
                    org = (from o in entity.Organizations
                           where o.Code == Userinfo.OrganizationName
                           select o).FirstOrDefault();
                }
                catch (Exception)
                {
                }
                if (org != null)
                {
                    Userdata = (from u in entity.UserInfoes
                                where u.OrganizationID == org.Id &&
                                u.LogInId == Userinfo.LogInId &&
                                u.UserPassword == Userinfo.UserPassword
                                select u).FirstOrDefault();
                    if (Userdata != null)
                    {
                        Userrole = (from ro in entity.UserRoles
                                    where ro.OrganizationID == org.Id &&
                                    ro.UserId == Userdata.Id &&
                                    ro.RowState == true
                                    select ro).FirstOrDefault();
                    }
                    var checkformail = (from mc in entity.EMailConfigurations
                                        where mc.OrganizationId == org.Id
                                        select mc).FirstOrDefault();
                    if (checkformail != null)
                    {
                        if (checkformail.AfterLoginMail == true)
                        {
                            sendmailper = true;
                        }
                    }
                }
            }
            if (Userdata != null && Userrole != null)
            {
                CustomPrincipalSerializeModel serializeModel = new CustomPrincipalSerializeModel();
                //FormsAuthentication.SetAuthCookie(Userdata.LogInId, true);

                serializeModel.OrgId = org.Id;
                //Session["OrgId"] = org.Id;

                // Session["OrgName"] = org.Name;
                serializeModel.OrgName = org.Name;

                //Session["UserId"] = Userdata.Id;
                serializeModel.UserId = Userdata.Id;

                //Session["UserName"] = Userdata.Name;
                serializeModel.UserName = Userdata.Name;

                //Session["ISApplicant"] = Userdata.IsApplicant;
                serializeModel.ISApplicant = Userdata.IsApplicant.ToString();

                if (Userrole != null)
                {
                    //Session["RoleId"] = Userrole.RoleId;
                    serializeModel.RoleId = Userrole.RoleId;
                }
                string userData = serializer.Serialize(serializeModel);
                //FormsAuthentication.SetAuthCookie(Userdata.LogInId, true);
                FormsAuthenticationTicket authTicket = new FormsAuthenticationTicket(
                    1,
                    Userinfo.LogInId,
                    DateTime.Now,
                    DateTime.Now.AddMinutes(15),
                    false,
                    userData.ToString(),
                    FormsAuthentication.FormsCookiePath);
                string     encTicket = FormsAuthentication.Encrypt(GetAuthTicket(GetAuthTicket1(authTicket: authTicket)));
                HttpCookie faCookie  = new HttpCookie(FormsAuthentication.FormsCookieName, GetEncTicket(encTicket));
                Response.Cookies.Add(cookie: faCookie);
                int cookieSize = Encoding.UTF8.GetByteCount(faCookie.Values.ToString());
                if (sendmailper == true)
                {
                    //getting client ip address
                    string ipAddress = Request.UserHostAddress.ToString();

                    //getting client browser name
                    string browserName = Request.Browser.Browser.ToString();

                    //getting client browser version



                    string body    = "Hi,Just now someone login to youe acocunt with IP:" + ipAddress + ",Browser:" + browserName + Request.Browser.Version.ToString() + ",If not you please contact us.";
                    string heading = "User login Details:";
                    if (Userdata.Email != null || Userdata.Email != "")
                    {
                        bool sendmail = SendMail(Userdata.Email, heading, body, null);
                    }
                }

                //var log = new logWriter("Login Successful for user:"******"UserHome"));
            }
            else
            {
                Session["InvalidUser"] = true;
                return(Redirect("/Home/Index"));
            }
        }