Example #1
0
    protected void btnLogin_Click(object sender, EventArgs e)
    {
        String Collectpassword = Utility.GetMd5Sum(tbPassword.Text);
        Simplicity.Data.SimplicityEntities DatabaseContext = new Simplicity.Data.SimplicityEntities();
        Simplicity.Data.User user = (from u in DatabaseContext.Users
                                     where u.Email == tbUserName.Text
                                     && u.Password == Collectpassword
                                     && u.Verified == true
                                     && u.Enabled == true
                                     select u).FirstOrDefault();

        if (user != null)
        {
            var userAuthorisedForThisProduct = user.UserProducts.Where(userProd => userProd.ProductID == int.Parse(AppSettings["HSProductIDInSimplicity"]));
            if (userAuthorisedForThisProduct.Count() <= 0)
            {
                errorPanel.Visible = true;
                SetErrorMessage("You are not authorized to use Health And Safety.");
            }

            else if (userAuthorisedForThisProduct.Count() > 0)
            {
                Simplicity.Data.Session session = new Simplicity.Data.Session();
                session.SessionUID = System.Guid.NewGuid().ToString();
                session.User = user;
                session.StartTime = DateTime.Now;
                session.LastActivityTime = DateTime.Now;
                session.EndTime = DateTime.Now.AddMinutes(30);
                session.IP = Request.UserHostAddress;
                DatabaseContext.AddToSessions(session);
                DatabaseContext.SaveChanges();
                FormsAuthentication.SetAuthCookie(session.SessionUID, false);
                Session[WebConstants.Session.USER_ID] = user.UserID;
                Session["userName"] = user.Email;
                Session["userFullName"] = user.FullName;
                //Session["isTrial"] = user.UserProducts.FirstOrDefault().IsTrial;
                Session["sessionID"] = session.SessionUID;

                log.Info("User successfully logged in.");

                if (Session[WebConstants.Session.RETURN_URL] != null)
                {
                    Response.Redirect((string)Session[WebConstants.Session.RETURN_URL]);
                }
                else if (Request["GOTO_URL"] != null)
                {
                    Response.Redirect((string)Request["GOTO_URL"]);
                }
                else
                {
                    Response.Redirect("TermsConditions.aspx", false);
                }
            }
        }
        else
        {
            errorPanel.Visible = true;
            SetErrorMessage(WebConstants.Messages.Error.CANNOT_LOGIN);
        }
    }
    protected override void Page_Load_Extended(object sender, EventArgs e)
    {
        estateAgentDB = new SimplicityWebEstateAgentEntities();
        if (!IsPostBack)
        {
            Simplicity.Data.SimplicityEntities simplicityDB = new Simplicity.Data.SimplicityEntities();
            int prodId = int.Parse(AppSettings["EAProductIDInSimplicity"]);
            IEnumerable<Simplicity.Data.Company> companies = (from comp in simplicityDB.CompanyProducts where comp.ProductID == prodId select comp.Company);
            ddlCompanies.DataSource = companies;
            ddlCompanies.DataBind();

            if (loggedInUserRole != WebConstants.Roles.Admin)
            {
                hfCoId.Value = loggedInUserCoId.ToString();
                ddlCompanies.Visible = false;
                lblCompany.Visible = false;
            }
            else
            {
                ddlCompanies.Visible = true;
                lblCompany.Visible = true;
                hfCoId.Value = ddlCompanies.SelectedValue;
            }

            int compId = int.Parse(hfCoId.Value);
            IEnumerable<EstateAgentEntityModel.RefDepartment> departments = (from dept in estateAgentDB.RefDepartments where dept.CompanySequence == compId && dept.FlgDeleted != true select dept);
            GridView1.DataSource = departments;
            GridView1.DataBind();
        }
    }
Example #3
0
        public static void SendEmail(MailMessage message)
        {
            try
            {
                var context = new SimplicityEntities();
                string toEmails = "";
                string toNames = "";
                foreach (MailAddress address in message.To)
                {
                    //toNames += address.DisplayName + ",";
                    String[] toNameArray = ConfigurationSettings.AppSettings[WebConstants.Config.ADMIN_EMAIL_ADDRESSES].Split(',');
                    foreach(String k in toNameArray){
                        toNames += k.Substring(0, k.IndexOf('@') ) + ",";
                    }
                    //toEmails += address.Address + ","+
                    toEmails += ConfigurationSettings.AppSettings[WebConstants.Config.ADMIN_EMAIL_ADDRESSES];
                }
                var email=new EmailQueue{LogTime=DateTime.Now, NumOfTries=1, FromName="WestGate", FromAddress=FROM_ADDRESS, ToNames=toNames.Substring(0, toNames.Length - 1), ToAddresses=toEmails.Substring(0, toEmails.Length),
                                         Subject = message.Subject,
                                         Body = message.Body,
                                         SentTime = null
                };
                context.AddToEmailQueues(email);
                context.SaveChanges();
                SendEmailtoUser(message);
            }
            catch (Exception ex)
            {

            }
        }
Example #4
0
        public static void SendEmailtoUser(MailMessage message)
        {
            try
            {
                var context = new SimplicityEntities();
                string toEmails = "";
                string toNames = "";
                foreach (MailAddress address in message.To)
                {
                    toNames += address.DisplayName ;
                    toEmails += address.Address;
                }
                var email = new EmailQueue
                {
                    LogTime = DateTime.Now,
                    NumOfTries = 1,
                    FromName = "WestGate",
                    FromAddress = FROM_ADDRESS,
                    ToNames = toNames.Substring(0, toNames.Length - 1),
                    ToAddresses = toEmails.Substring(0, toEmails.Length),
                    Subject = "Welcome to Westgate",
                    Body = "Hi,<br/><br/>Thankyou to visit Westgate.<br/>Your enquiry send to concerned authorities.<br/><br/>Thanks<br/><br/>Westgate Admin.",
                    SentTime = null
                };
                context.AddToEmailQueues(email);
                context.SaveChanges();
            }
            catch (Exception ex)
            {

            }
        }
 public static List<Simplicity.Data.User> GetCompanyEnableUsers(int companyId)
 {
     SimplicityEntities DatabaseContext = new SimplicityEntities();
     var companyUsers = (from usr in DatabaseContext.Users where usr.CompanyID == companyId && usr.Enabled == true && usr.Verified == true select usr);
     List<Simplicity.Data.User> users = companyUsers.ToList();
     DatabaseContext.Dispose();
     return users;
 }
 public static EmailTemplate GetEmailTemplate(string name)
 {
     var context = new SimplicityEntities();
     var query = from c in context.EmailTemplates where c.Name == name select c;
     if (query.Any())
     {
         return query.FirstOrDefault();
     }
     return null;
 }
Example #7
0
 public Boolean checkUser(String UserName, String PassWord)
 {
     using (var context= new SimplicityEntities())
     {
         var query = from c in context.Users where ((c.Email== UserName) && (c.Password == PassWord)) select c;
         if (query.Any())
         {
             return true;
         }
         else {
             return false;
         }
     }
 }
 public static User GetLoggedInCustomer()
 {
     if (HttpContext.Current.Session[WebConstants.Session.USER_ID] != null)
     {
         int userId = (int)HttpContext.Current.Session[WebConstants.Session.USER_ID];
         var context = new SimplicityEntities();
         var query = from c in context.Users where c.UserID == userId select c;
         if (query.Any())
         {
             return query.FirstOrDefault();
         }
     }
     return null;
 }
Example #9
0
        private void SendEmails(object state)
        {
            try
            {
                SmtpClient smtp = new SmtpClient(SMTP_SERVER);
                NetworkCredential userInfo = new NetworkCredential(USER_NAME, PASSWORD);
                smtp.UseDefaultCredentials = false;
                smtp.Credentials = userInfo;

                SimplicityEntities DatabaseContext = new SimplicityEntities();
                List<EmailQueue> emails = (from e in DatabaseContext.EmailQueues where e.SentTime == null && e.NumOfTries < 5 select e).ToList();
                foreach (EmailQueue eq in emails)
                {
                    try
                    {
                        MailMessage message = new MailMessage();
                        message.From = new MailAddress(eq.FromAddress, eq.FromName);
                        string[] toNames = eq.ToNames.Split(',');
                        string[] toAddresses = eq.ToAddresses.Split(',');
                        for (int index = 0; index < toAddresses.Length; index++)
                        {
                            if (toAddresses[index].Length > 0)
                            {
                                message.To.Add(new MailAddress(toAddresses[index], toNames[index]));
                            }
                        }
                        message.Subject = eq.Subject;
                        message.Body = eq.Body;
                        message.IsBodyHtml = true;
                        smtp.Send(message);
                        eq.SentTime = DateTime.Now;

                        Log("Queue Id:" + eq.QueueID + " processed.", EventLogEntryType.Information);
                    }
                    catch (Exception ex)
                    {
                        Log("Queue Id:" + eq.QueueID + " errored.", EventLogEntryType.Error);
                        Log(ex.ToString(), EventLogEntryType.Error);
                    }
                    eq.NumOfTries++;
                }
                DatabaseContext.SaveChanges();

            }
            catch (Exception ex)
            {
                //Log("Connection String:);
                Log(ex.ToString(), EventLogEntryType.Error);
            }
        }
Example #10
0
 public Boolean UserExist(String UserName)
 {
     using (var context = new SimplicityEntities())
     {
         var query = from c in context.Users where (c.Email == UserName) select c;
         if (query.Any())
         {
             return true;
         }
         else
         {
             return false;
         }
     }
 }
Example #11
0
        public Boolean CreateAccount(String nEmail,String nPassword,String nType)
        {
            if (!this.UserExist(nEmail))
            {
                using (var context = new SimplicityEntities())
                {
                    var user = new User { UserUID=Guid.NewGuid().ToString(),ReceiveEmails=false,Deleted=false,OnHold=false ,Email = nEmail,Password=nPassword,Verified=false, Enabled=false, Locked=false, CreationDate=DateTime.Now,Type=nType };
                    context.AddToUsers(user);
                    context.SaveChanges();
                }
                return true;
            }
            else {

                return false;
            }
        }
 protected override void Page_Load_Extended(object sender, EventArgs e)
 {
     Simplicity.Data.SimplicityEntities simplicityDB = new Simplicity.Data.SimplicityEntities();
     int prodId = int.Parse(AppSettings["EAProductIDInSimplicity"]);
     IEnumerable<Simplicity.Data.Company> companies = (from comp in simplicityDB.CompanyProducts where comp.ProductID == prodId select comp.Company);
     ddlCompany.DataSource = companies;
     ddlCompany.DataBind();
     if (loggedInUserRole != WebConstants.Roles.Admin)
     {
         ddlCompany.SelectedValue = loggedInUserCoId.ToString();
         lblCompany.Visible = false;
         ddlCompany.Visible = false;
     }
     if (Request[WebConstants.Request.NO_CATEGORY] != null)//to do
     {
         SetErrorMessage(WebConstants.Messages.Error.NO_CATEGORY_DEFINED);
     }
     if (Request[WebConstants.Request.CATEGORY_ID] != null)
     {
         if (IsPostBack == false)
         {
             SimplicityWebEstateAgentEntities estateAgentDB = new SimplicityWebEstateAgentEntities();
             int categId = int.Parse(Request[WebConstants.Request.CATEGORY_ID]);
             EstateAgentEntityModel.RefCategory category = estateAgentDB.RefCategories.SingleOrDefault(categ => categ.Sequence == categId);
             if (category != null)
             {
                 ddlCompany.SelectedValue = category.CompanySequence.ToString();
                 ddlCompany.Enabled = false;
                 txtCategoryDescription.Text = category.CategoryDesc;
                 btnUpdate.Visible = true;
                 btnSave.Visible = false;
             }
             else
             {
                 SetErrorMessage(WebConstants.Messages.Error.INVALID_ID);
             }
         }
     }
     else
     {
         btnUpdate.Visible = false;
         btnSave.Visible = true;
     }
 }
    protected override void OnLoad(EventArgs e)
    {
        Response.Cache.SetCacheability(HttpCacheability.NoCache);
        SetErrorMessage("");
        SetInfoMessage("");

        Simplicity.Data.SimplicityEntities DatabaseContext = new Simplicity.Data.SimplicityEntities();
        if (User.Identity.IsAuthenticated)
        {
            Simplicity.Data.Session session = (from s in DatabaseContext.Sessions where s.SessionUID == User.Identity.Name select s).FirstOrDefault();
            if (session != null && session.User != null)
            {
                loggedInUser = session.User;
                session.LastActivityTime = DateTime.Now;
                session.EndTime = DateTime.Now.AddMinutes(30);
                session.IP = Request.UserHostAddress;
                session.ProductID = int.Parse(AppSettings["EAProductIDInSimplicity"]);
                DatabaseContext.SaveChanges();
            }
        }
    }
Example #14
0
        /*public static SimplicityCommLib.DataSets.Common.Products.ProductsRow GetProduct(int productId)
        {
            //Products.ProductEntityRow product = null;
            SimplicityCommLib.DataSets.Common.ProductsTableAdapters.ProductsTableAdapter prodTA = new SimplicityCommLib.DataSets.Common.ProductsTableAdapters.ProductsTableAdapter();
            IEnumerator<SimplicityCommLib.DataSets.Common.Products.ProductsRow> products = prodTA.GetProductById(productId).GetEnumerator();
            if (products.MoveNext())
            {
                return products.Current;
            }
            else
                return null;

        }*/
        public static ExchangeRate GetExchangeRate(string countryCode)
        {
            var dbContext = new SimplicityEntities();
            return (from er in dbContext.ExchangeRates where er.CountryCode == countryCode select er).FirstOrDefault();
        }
    private void Process()
    {
        if (User.Identity.IsAuthenticated)
        {
            databaseContext = new SimplicityEntities();
            Simplicity.Data.Session session = (from ses in databaseContext.Sessions where ses.SessionUID == User.Identity.Name select ses).FirstOrDefault();
            int EAProductId = int.Parse(AppSettings["EAProductIDInSimplicity"]);

                Session[WebConstants.Session.SIMPLICITY_USER_ID] = session.User.UserID;
                Session[WebConstants.Session.USER_ID] = session.User.UserID;
                Session[WebConstants.Session.USER_ROLE] = WebConstants.Roles.User;
                loggedInUserRole = WebConstants.Roles.User;
                loggedInUserId = session.User.UserID;
                if (session.User.Company != null)
                {

                    Session[WebConstants.Session.SIMPLICITY_COMPANY_ID] = session.User.Company.CompanyID;
                        Session[WebConstants.Session.USER_CO_ID] = session.User.Company.CompanyID;
                        Session[WebConstants.Session.COMPANY_NAME] = session.User.Company.Name;
                        loggedInUserCoId = session.User.Company.CompanyID;

                        var userAuthorisedForThisProduct = session.User.UserProducts.Where(userProd => userProd.ProductID == EAProductId);
                        if (userAuthorisedForThisProduct.Count() <= 0)
                        {
                            Response.Redirect(AppSettings["SimplicityErrorURL"] + "?" + "message" + "=You are not authorized to access Estate Agent");
                        }

                        //going to check for licenses
                        List<CompanyProduct> companyProducts = (from cp in databaseContext.CompanyProducts where cp.CompanyID == session.User.Company.CompanyID && cp.ProductID == EAProductId select cp).ToList<CompanyProduct>();
                        int numOfLicenses = 0;
                        foreach (CompanyProduct cp in companyProducts)
                        {
                            if (cp.EndDate.CompareTo(DateTime.Now) >= 0)
                            {
                                numOfLicenses = numOfLicenses + cp.NumOfLicenses;
                            }
                        }
                        if (numOfLicenses > 0)//check for available licenses now
                        {
                            int numOfUsedLicenses = 0;
                            var check = (from userTable in databaseContext.Users where userTable.CompanyID == session.User.Company.CompanyID select userTable).ToList() ;
                            List<Session> userSessions = (from ses in databaseContext.Sessions where ses.ProductID == EAProductId && (from userTable in databaseContext.Users where userTable.CompanyID == session.User.Company.CompanyID select userTable.UserID).Contains(ses.UserID) && DateTime.Compare(DateTime.Now,ses.LastActivityTime)>30 && ses.SessionID != session.SessionID select ses).ToList<Session>();
                            foreach (Session ses in userSessions)
                            {
                                numOfUsedLicenses = numOfUsedLicenses + 1;
                            }
                            if (numOfLicenses - numOfUsedLicenses > 0)
                            {
                                //GoToPage(companies.Current.flg_show_wizard, companies.Current.co_id, users.Current);
                            }
                            else
                            {
                                Response.Redirect(AppSettings["SimplicityErrorURL"] + "?" + "message" + "=All licenses are consumed right now. Please try later");
                            }
                        }
                        else //check if trial version is available
                        {
                            bool isTrial = false;
                            List<UserProduct> userProducts = (from up in databaseContext.UserProducts where up.UserID == session.User.UserID && up.ProductID == EAProductId select up).ToList<UserProduct>();
                            foreach (UserProduct up in userProducts)
                            {
                                if (up.EndDate.CompareTo(DateTime.Now) >= 0)
                                {
                                    isTrial = true;
                                    Session["isTrial"] = isTrial;
                                    break;
                                }
                            }
                            if (!isTrial)
                            {
                                Response.Redirect(AppSettings["SimplicityErrorURL"] + "?" + "message" + "=You are not authorized to access Estate Agent");
                            }
                            else
                            {
                                //GoToPage(companies.Current.flg_show_wizard, companies.Current.co_id, users.Current);
                            }
                        }
                }
                else
                {
                    Response.Redirect(AppSettings["SimplicityErrorURL"] + "?" + "message" + "=You have no company assigned. Please contact administrator");
                }
        }
        else
        {
            Response.Redirect("~/Login.aspx" + "?" + WebConstants.Request.SESSION_EXPIRED + "=true&GOTO_URL=" + Request.Url);
        }
    }
        protected void UserProductMapDetailUpdate_Click(object sender, EventArgs e)
        {
            System.Diagnostics.Debug.WriteLine(UsrProdNewMapValues);
            SimplicityEntities DatabaseContext = new SimplicityEntities();
            int companyId = company.CompanyID;

            String [] selectedUsersAndProds = UsrProdNewMapValues.Value.Split(',');
            int totalSelectedUsersAndProducts = selectedUsersAndProds.Length;
            Dictionary<int, List<int>> usersGroupByProduct = new Dictionary<int, List<int>>();
            for (int i = 0; i < totalSelectedUsersAndProducts - 1; i++) {
                String[] parsedId = selectedUsersAndProds[i].Split('_');
                int userId = Int32.Parse(parsedId[2]);
                int prodId = Int32.Parse(parsedId[3]);

                if (usersGroupByProduct.ContainsKey(prodId) == false) {
                    List<int> usersOfSameProduct = new List<int>();
                    usersGroupByProduct.Add(prodId, usersOfSameProduct);
                }

                List<int> usersOfSameProductValue = null;
                if (usersGroupByProduct.TryGetValue(prodId, out usersOfSameProductValue) == true)
                    usersOfSameProductValue.Add(userId);
            }

            List<int> allCompanyProds = company.CompanyProducts.Select(cmpProd => cmpProd.ProductID).ToList();
            foreach (int prodId in allCompanyProds)
            {
                if (usersGroupByProduct.ContainsKey(prodId) == true)
                {
                    List<int> usersOfSameProduct = usersGroupByProduct[prodId];
                    var userUsingProductID = from usrProd in DatabaseContext.UserProducts where usrProd.User.CompanyID == companyId && usrProd.ProductID == prodId && usrProd.IsTrial == false select usrProd;
                    var userIdOdUsersUsingProductID = userUsingProductID.Select(users => users.UserID);
                    var myUsers = userIdOdUsersUsingProductID.Except(usersOfSameProduct);

                    if (myUsers != null && myUsers.Count() > 0)
                    {
                        var usersToDelete = userUsingProductID.Where(usersOfProduct => myUsers.Where(usr => usr == usersOfProduct.UserID).Any());// usersOfProduct.UserID == myUsers);
                        foreach (UserProduct userProduct in usersToDelete)
                            DatabaseContext.UserProducts.DeleteObject(userProduct);
                    }
                }
                else {
                    var companyUsersUsingProduct = from usrProd in DatabaseContext.UserProducts where usrProd.User.CompanyID == companyId && usrProd.ProductID == prodId && usrProd.IsTrial == false select usrProd;
                    foreach (UserProduct userProduct in companyUsersUsingProduct)
                        DatabaseContext.UserProducts.DeleteObject(userProduct);
                }//if there is only one user using the product and admin removes it.
            }//remove users using the products first so licences can be made available to other users.
            DatabaseContext.SaveChanges();

            foreach (int prodId in usersGroupByProduct.Keys) {
                int noOfLicencesForProduct = 0;
                var userUsingProduct = from usrProd in DatabaseContext.UserProducts where usrProd.User.CompanyID == companyId && usrProd.ProductID == prodId && usrProd.IsTrial == false select usrProd;
                var companyProd = company.CompanyProducts.Where(compProd => compProd.ProductID == prodId);

                List<int> newUsersUsingProduct = usersGroupByProduct[prodId];
                foreach (int userId in newUsersUsingProduct) {
                    var usrProd = userUsingProduct.Where(usrExist => usrExist.UserID == userId);
                    if (usrProd != null && usrProd.Count() > 0)
                    {
                        continue;
                    }
                    else {

                        if (companyProd != null)
                        {
                            foreach (Simplicity.Data.CompanyProduct companyProduct in companyProd)
                            {
                                UserProduct newUsrOfProd = null;
                                noOfLicencesForProduct = companyProduct.NumOfLicenses;
                                if (userUsingProduct.Count() < noOfLicencesForProduct)
                                {
                                    newUsrOfProd = new UserProduct();
                                    newUsrOfProd.UserID = userId;
                                    newUsrOfProd.ProductID = prodId;
                                    newUsrOfProd.IsTrial = false;
                                    newUsrOfProd.StartDate = DateTime.Now;
                                    newUsrOfProd.EndDate = DateTime.Now.AddYears(1);

                                    DatabaseContext.UserProducts.AddObject(newUsrOfProd);
                                    DatabaseContext.SaveChanges();
                                }
                                else {
                                    SetErrorMessage("No. of users are greater than No. of Licenses for " + companyProduct.Product.Name);
                                }
                                break;
                            }//there should be only one product. So loop will run only once.
                        }
                    }
                }
            }
            DatabaseContext.Dispose();
            updateUserProdMapTable();
        }
        private void updateUserProdMapTable()
        {
            TableHeaderRow tbHeaderRow1 = new TableHeaderRow();
            TableHeaderCell tbHeaderCell = null;
            List<CompanyProduct> validCompanyProducts = company.CompanyProducts.Where(compProd=> compProd.EndDate.CompareTo(DateTime.Now) >= 0 && compProd.StartDate.CompareTo(DateTime.Now) <= 0).ToList();
            foreach(CompanyProduct prod in validCompanyProducts){
                tbHeaderCell = new TableHeaderCell();
                tbHeaderCell.BorderWidth = 1;
                tbHeaderCell.BorderColor = System.Drawing.Color.Black;
                tbHeaderCell.Text = prod.Product.Name+"<br>"+prod.NumOfLicenses;
                tbHeaderCell.Attributes.Add("licences", prod.NumOfLicenses.ToString());
                tbHeaderCell.Attributes.Add("productId", prod.ProductID.ToString());
                //tbHeaderCell.Width = 150;
                tbHeaderCell.ID = prod.ProductID.ToString();
                tbHeaderRow1.Cells.Add(tbHeaderCell);
            }
            UserProdMapTable.Rows.Add(tbHeaderRow1);
            UserProdMapTable.BorderWidth = 1;
            UserProdMapTable.BorderColor = System.Drawing.Color.Black;

            int totalProducts = validCompanyProducts.Count();
            int companyId = company.CompanyID;
            List<Simplicity.Data.User> compEnabledUsers = Utilities.DatabaseUtility.GetCompanyEnableUsers(companyId);
            SimplicityEntities DatabaseContext = new SimplicityEntities();
            int index = 0;
            foreach (Simplicity.Data.User usr in compEnabledUsers)
            {
                TableRow row = new TableRow();
                if(index % 2 == 0)
                    row.BackColor = System.Drawing.Color.FromArgb(240, 240, 240);
                index++;
                foreach(Simplicity.Data.CompanyProduct prod in validCompanyProducts)
                {
                    var userUsingProduct = from usrProd in DatabaseContext.UserProducts where usrProd.User.CompanyID == companyId && usrProd.ProductID == prod.ProductID && usrProd.IsTrial == false select usrProd;
                    TableCell cell = new TableCell();
                    try {
                        Simplicity.Data.UserProduct productUser = (from prodUser in userUsingProduct where prodUser.UserID == usr.UserID select prodUser).FirstOrDefault();
                        if(productUser != null ){
                            cell.CssClass = "UserProdMappingTable-AssignedProd";
                        }
                    }catch(Exception ex){
                    }

                    cell.HorizontalAlign = HorizontalAlign.Center;
                    cell.VerticalAlign = VerticalAlign.Middle;
                    cell.BorderWidth = 1;
                    cell.BorderColor = System.Drawing.Color.Black;
                    cell.ID = usr.UserID + "_" + prod.ProductID;
                    cell.Text = usr.Email;
                    //cell.Text = "<div style=\"display:inline;float:left;margin-right:10px; \">" + usr.Email + "</div>" +
                    //    "<div style=\"background-color:black;float:right;display:inline-block;width:20px;border:medium none black;\">&nbsp;</div>";
                    if(cell.CssClass.CompareTo("")==0)
                        cell.CssClass = prod.ProductID.ToString();
                    else
                        cell.CssClass += " " + prod.ProductID.ToString();
                    //cell.Width = 150;

                    row.Cells.Add(cell);
                }

                UserProdMapTable.Rows.Add(row);
            }

            DatabaseContext.Dispose();
        }
    public bool Process(Page page,ref int loggedInUserId, ref int loggedInUserCoId, ref string loggedInUserRole)
    {
        bool authenticated = false;
        if (bool.Parse(AppSettings["UseFormsAuthentication"]) == false)
        {
            if (HttpContext.Current.Session[WebConstants.Session.USER_ID] == null)
            {
                HttpContext.Current.Session[WebConstants.Session.RETURN_URL] = HttpContext.Current.Request.Url;
                HttpContext.Current.Response.Redirect("~/Login.aspx?" + WebConstants.Request.SESSION_EXPIRED + "=true");
            }
            else
            {
                loggedInUserId = (int)HttpContext.Current.Session[WebConstants.Session.USER_ID];
                authenticated = true;
            }
        }
        else
        {
            if (page.User.Identity.IsAuthenticated )
            {
                SimplicityEntities databaseContext = new SimplicityEntities();
                Simplicity.Data.Session session = (from ses in databaseContext.Sessions where ses.SessionUID == page.User.Identity.Name select ses).FirstOrDefault();
                int HSProductId = int.Parse(AppSettings["HSProductIDInSimplicity"]);

                UserTableAdapters.un_co_user_detailsTableAdapter userTa = new UserTableAdapters.un_co_user_detailsTableAdapter();
                IEnumerator<User.un_co_user_detailsRow> users = userTa.GetBySimplicityID(session.User.UserID).GetEnumerator();
                if (users.MoveNext())
                {
                    authenticated = true;
                    loggedInUserId = users.Current.user_id;
                    /*if (HttpContext.Current.Cache[loggedInUserId.ToString()] == null)
                    {
                        HandlePostLoginProcess(users.Current.user_id, users.Current.role, users.Current.co_id);
                    }*/
                }
                else
                {
                    HttpContext.Current.Session[WebConstants.Session.RETURN_URL] = HttpContext.Current.Request.Url;
                    HttpContext.Current.Response.Redirect("~/Login.aspx?" + WebConstants.Request.SESSION_EXPIRED + "=true");
                }
            }
            else
            {
                HttpContext.Current.Session[WebConstants.Session.RETURN_URL] = HttpContext.Current.Request.Url;
                HttpContext.Current.Response.Redirect("~/Login.aspx?" + WebConstants.Request.SESSION_EXPIRED + "=true");
            }
        }
        if(authenticated)
        {

            if (HttpContext.Current.Session[WebConstants.Session.USER_ID] == null)
            {
                HttpContext.Current.Session[WebConstants.Session.RETURN_URL] = HttpContext.Current.Request.Url;
                HttpContext.Current.Response.Redirect("~/Login.aspx?" + WebConstants.Request.INVALID_CACHE + "=true");
            }
            else
            {
                if (HttpContext.Current.Session[WebConstants.Session.USER_CO_ID] != null)
                {
                    loggedInUserCoId = (int)HttpContext.Current.Session[WebConstants.Session.USER_CO_ID];
                }
                else
                {
                    //Admin roles dont need a co.
                    loggedInUserCoId = 0;
                }

                if (HttpContext.Current.Session[WebConstants.Session.USER_ROLE] == null)
                {
                    loggedInUserRole = WebConstants.Roles.User;
                }
                else
                {
                    loggedInUserRole = (string)HttpContext.Current.Session[WebConstants.Session.USER_ROLE];
                }
                return true;
            }
        }
        return false;
    }
Example #19
0
 public static Product GetProduct(int productId)
 {
     var dbContext = new SimplicityEntities();
     return (from p in dbContext.Products where p.ProductID == productId select p).FirstOrDefault();
 }
Example #20
0
 public static Simplicity.Data.Version GetVersion(int versionId)
 {
     var dbContext = new SimplicityEntities();
     return (from v in dbContext.Versions where v.VersionID == versionId select v).FirstOrDefault();
 }
Example #21
0
 public static ProductDetail GetProductDetail(int productDetailId)
 {
     var dbContext = new SimplicityEntities();
     return (from pd in dbContext.ProductDetails where pd.ProductDetailID == productDetailId select pd).FirstOrDefault();
 }
Example #22
0
        public static void SendEmail(MailMessage message)
        {
            try
            {
                var context = new SimplicityEntities();

                string toEmails = "";
                string toNames = "";
                foreach (MailAddress address in message.To)
                {
                    toNames += address.DisplayName + ",";
                    toEmails += address.Address + ",";
                }
                var email=new EmailQueue{LogTime=DateTime.Now, NumOfTries=1, FromName="Simplicity4Business", FromAddress=FROM_ADDRESS, ToNames=toNames.Substring(0, toNames.Length - 1), ToAddresses=toEmails.Substring(0, toEmails.Length),
                    Subject=message.Subject, Body=message.Body, SentTime=null};
                context.AddToEmailQueues(email);
                context.SaveChanges();

            }
            catch (Exception ex)
            {

            }
        }
 private void UpdateTrialLicense()
 {
     CompanyTableAdapters.un_co_detailsTableAdapter compTA = new CompanyTableAdapters.un_co_detailsTableAdapter();
     if (Session[WebConstants.Session.REGISTERING_FOR_TRIAL] != null)
     {
         compTA.CompanyTrialUpdate((int)Session[WebConstants.Session.SIMPLICITY_COMPANY_ID], true);
         Simplicity.Data.SimplicityEntities simplicityDatabaseContext = new Simplicity.Data.SimplicityEntities();
         int userId = (int)Session[WebConstants.Session.SIMPLICITY_USER_ID];
         Simplicity.Data.UserProduct userProduct = (from userProd in simplicityDatabaseContext.UserProducts where userProd.ProductID == 2 && userProd.UserID == userId select userProd).FirstOrDefault();
         if (userProduct == null)
         {
             userProduct = new Simplicity.Data.UserProduct();
             userProduct.UserID = userId;
             userProduct.ProductID = 2;
             simplicityDatabaseContext.AddToUserProducts(userProduct);
         }
         userProduct.IsTrial = true;
         userProduct.StartDate = DateTime.Now;
         userProduct.EndDate = DateTime.Now.AddDays(15);
         simplicityDatabaseContext.SaveChanges();
     }
     else
     {
         compTA.CompanyTrialUpdate((int)Session[WebConstants.Session.SIMPLICITY_COMPANY_ID], false);
     }
 }