protected void AddAdminDetails_Click(object sender, EventArgs e)
        {
            try
            {
                string RandomPassword = Path.GetRandomFileName();
                RandomPassword = RandomPassword.Replace(".", "");

                NasaFitnessDbDataContext nasaFitnessDbDataContext = new NasaFitnessDbDataContext
                                                                        ("Server=tcp:nasafitness.database.windows.net,1433;Initial Catalog=nasafitnessllc;Persist Security Info=False;User ID=dr_nasafitness;Password=Conversion2016;MultipleActiveResultSets=False;Encrypt=True;TrustServerCertificate=False;Connection Timeout=30;");

                nasafitness nasafitness = new nasafitness
                {
                    user_name        = AdminName.Text,
                    company_name     = CompanyName.Text,
                    position         = Position.SelectedValue,
                    email_id         = EmailID.Text,
                    pass_word        = RandomPassword,
                    administrator    = 0,
                    company_location = CompanyLocation.Text
                };

                company_detail company_Detail = new company_detail
                {
                    company_name  = CompanyName.Text,
                    location_name = CompanyLocation.Text
                };

                nasaFitnessDbDataContext.company_details.InsertOnSubmit(company_Detail);
                nasaFitnessDbDataContext.nasafitnesses.InsertOnSubmit(nasafitness);
                nasaFitnessDbDataContext.SubmitChanges();
                nasaFitnessDbDataContext.Dispose();

                // Creates a MailMessage
                MailMessage mail = new MailMessage("*****@*****.**", EmailID.Text);
                mail.Subject = "Auto Generated Reply from NasaFitness";
                mail.Body    = $"You are now successfully added as Admin with password : {RandomPassword}";

                // Username and Password of Sender
                SmtpClient smtpClient = new SmtpClient("smtp.gmail.com", 587);
                smtpClient.Credentials = new NetworkCredential("*****@*****.**", "sandhya3654");
                smtpClient.EnableSsl   = true;
                smtpClient.Send(mail);

                AdminDetailsMessage.Visible = true;
            }
            catch (Exception ex)
            {
            }
        }
        protected void AddLocation_Click(object sender, EventArgs e)
        {
            NasaFitnessDbDataContext nasaFitnessDbDataContext = new NasaFitnessDbDataContext
                                                                    ("Server=tcp:nasafitness.database.windows.net,1433;Initial Catalog=nasafitnessllc;Persist Security Info=False;User ID=dr_nasafitness;Password=Conversion2016;MultipleActiveResultSets=False;Encrypt=True;TrustServerCertificate=False;Connection Timeout=30;");

            company_detail company_Detail = new company_detail
            {
                location_name = Location.Text,
            };

            nasaFitnessDbDataContext.company_details.InsertOnSubmit(company_Detail);
            nasaFitnessDbDataContext.SubmitChanges();

            nasaFitnessDbDataContext.Dispose();
            Message.Text    = "Company added successfully";
            Message.Visible = true;
        }
Example #3
0
        protected void AdminSubmit_Click(object sender, EventArgs e)
        {
            NasaFitnessDbDataContext nasaFitnessDbDataContext = new NasaFitnessDbDataContext
                                                                    ("Server=tcp:nasafitness.database.windows.net,1433;Initial Catalog=nasafitnessllc;Persist Security Info=False;User ID=dr_nasafitness;Password=Conversion2016;MultipleActiveResultSets=False;Encrypt=True;TrustServerCertificate=False;Connection Timeout=30;");

            var administratorvalue = nasaFitnessDbDataContext.nasafitnesses.Where(m => m.user_name == UserName.Text && m.pass_word == AdminPassword.Value).Select(m => m.administrator).SingleOrDefault();

            Session.Add("adminuser", administratorvalue);
            Session.Add("username", UserName.Text);
            if (administratorvalue is null)
            {
                Response.Write("<script>alert('Invalid Username or Password')</script>");
            }
            else
            {
                Response.Redirect("AssignRole.aspx?Admin=" + administratorvalue + "&?LoginUser=" + UserName.Text);
            }

            nasaFitnessDbDataContext.Dispose();
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            // Add Data to Company Details Drop down
            NasaFitnessDbDataContext nasaFitnessDbDataContext = new NasaFitnessDbDataContext
                                                                    ("Server=tcp:nasafitness.database.windows.net,1433;Initial Catalog=nasafitnessllc;Persist Security Info=False;User ID=dr_nasafitness;Password=Conversion2016;MultipleActiveResultSets=False;Encrypt=True;TrustServerCertificate=False;Connection Timeout=30;");

            IList <string> companyDetails = nasaFitnessDbDataContext.company_details.Select(m => m.company_name).Distinct().ToList <string>();

            foreach (var company in companyDetails)
            {
                CompanyName.Items.Add(company);
            }

            IList <string> locationDetails = nasaFitnessDbDataContext.company_details.Select(m => m.location_name).Distinct().ToList <string>();

            foreach (var location in locationDetails)
            {
                CompanyLocation.Items.Add(location);
            }
            nasaFitnessDbDataContext.Dispose();
        }
        protected void CompanyReports_Click(object sender, EventArgs e)
        {
            NasaFitnessDbDataContext nasaFitnessDbDataContext = new NasaFitnessDbDataContext
                                                                    ("Server=tcp:nasafitness.database.windows.net,1433;Initial Catalog=nasafitnessllc;Persist Security Info=False;User ID=dr_nasafitness;Password=Conversion2016;MultipleActiveResultSets=False;Encrypt=True;TrustServerCertificate=False;Connection Timeout=30;");

            var user = Session["username"].ToString();

            var accesslevel = nasaFitnessDbDataContext.nasafitnesses.Where(m => m.user_name == user).Select(m => m.access_level).SingleOrDefault();

            if (accesslevel == 2 || accesslevel == 1)
            {
                string[]        filePaths = Directory.GetFiles("C:\\Users\\chinnu\\Desktop\\old\\WebApplication\\WebApplication\\Content\\CompanyReports\\");
                List <ListItem> files     = new List <ListItem>();
                foreach (string filePath in filePaths)
                {
                    files.Add(new ListItem(Path.GetFileName(filePath), filePath));
                }
                GridView1.DataSource = files;
                GridView1.DataBind();
            }
        }
        protected void ChangePasswordButton_Click(object sender, EventArgs e)
        {
            var username = Session["username"].ToString();
            NasaFitnessDbDataContext nasaFitnessDbDataContext = new NasaFitnessDbDataContext
                                                                    ("Server=tcp:nasafitness.database.windows.net,1433;Initial Catalog=nasafitnessllc;Persist Security Info=False;User ID=dr_nasafitness;Password=Conversion2016;MultipleActiveResultSets=False;Encrypt=True;TrustServerCertificate=False;Connection Timeout=30;");

            var entity = nasaFitnessDbDataContext.nasafitnesses.Where(m => m.user_name == username).SingleOrDefault();

            if (entity is null)
            {
                Response.Write("<script>alert('User does not Exist.')</script>");
            }
            else
            {
                if (entity.pass_word.Equals(OldPassword.Text))
                {
                    if (ConfirmPassword.Text.Equals(CurrentPassword.Text))
                    {
                        nasafitness result = (from p in nasaFitnessDbDataContext.nasafitnesses
                                              where p.pass_word == OldPassword.Text
                                              select p).SingleOrDefault();

                        result.pass_word = CurrentPassword.Text;
                        nasaFitnessDbDataContext.SubmitChanges();
                        Response.Write("<script>alert('Password Changes Successfully.')</script>");
                    }
                    else
                    {
                        Response.Write("<script>alert('Old and New Password does not Match.')</script>");
                    }
                }
                else
                {
                    Response.Write("<script>alert('Old Password is Invalid.')</script>");
                }
            }

            nasaFitnessDbDataContext.Dispose();
        }