Пример #1
0
        public ActionResult Create_Workers(tbl_user user)
        {
            var autopassword = "";

            if (Session["User_Id"] != null)
            {
                int getstatusID = Convert.ToInt32(Request.Form["Status_hidden"]);
                if (getstatusID == 0)
                {
                    getstatusID = 1;
                }
                using (jugglecontext dbcon = new jugglecontext())
                {
                    try
                    {
                        var      userId = Convert.ToInt32(Session["User_Id"]);
                        tbl_user tblusr = new tbl_user();
                        tblusr.firstName     = user.firstName.Trim();
                        tblusr.lastName      = user.lastName.Trim();
                        tblusr.address       = user.address.Trim();
                        tblusr.phoneno       = user.phoneno.Trim();
                        tblusr.email         = user.email.Trim();
                        tblusr.username      = user.username.Trim();
                        autopassword         = dbcon.GeneratePassword(6).Trim();
                        tblusr.password      = dbcon.Encrypt(autopassword.Trim());
                        tblusr.created_date  = DateTime.Now;
                        tblusr.status        = getstatusID;
                        tblusr.supervisor_id = userId;
                        tblusr.role_id       = 3;
                        tblusr.user_id       = userId;
                        dbcon.tbl_user.Add(tblusr);
                        dbcon.SaveChanges();

                        string Password = autopassword;
                        string Body     = "Your password '" + Password + "' ";
                        dbcon.SendMail(tblusr.email, "Password", Body, Password);

                        return(RedirectToAction("ManageWorkers", "Workers"));
                    }
                    catch (DbEntityValidationException ex)
                    {
                        foreach (var entityValidationErrors in ex.EntityValidationErrors)
                        {
                            foreach (var validationError in entityValidationErrors.ValidationErrors)
                            {
                                Response.Write("Property: " + validationError.PropertyName + " Error: " + validationError.ErrorMessage);
                            }
                        }
                        return(View(user));
                    }
                }
            }
            else
            {
                return(View(user));
            }
        }
Пример #2
0
        public ActionResult changePassword(changePassword changepass)
        {
            if (Session["User_Id"] != null)
            {
                using (jugglecontext dbcon = new jugglecontext())
                {
                    var      old_pass = changepass.oldPassword.ToString().Trim();
                    var      new_pass = dbcon.Encrypt(changepass.NewPassword.ToString());
                    tbl_user user     = null;

                    var    user_id = Convert.ToInt32(Session["User_Id"].ToString());
                    string password_fromdb;
                    var    getuser_pass = dbcon.tbl_user.SingleOrDefault(user_id_db => user_id_db.user_id == user_id);
                    user = dbcon.tbl_user.Where(s => s.user_id == user_id).FirstOrDefault <tbl_user>();
                    if (getuser_pass != null)
                    {
                        password_fromdb = dbcon.Decrypt(getuser_pass.password.ToString());
                        if (password_fromdb == old_pass)
                        {
                            user.password = Convert.ToString(new_pass);

                            dbcon.tbl_user.Attach(user);
                            dbcon.Entry(user).State = System.Data.Entity.EntityState.Modified;
                            dbcon.SaveChanges();
                            ViewBag.message = "Your password has been changed.";
                        }
                        else
                        {
                            if (string.IsNullOrEmpty(old_pass))
                            {
                                ModelState.AddModelError("oldPassword", "Please enter old password.");
                            }
                            else
                            {
                                ModelState.AddModelError("", "Invalid old password!");
                            }
                        }
                    }
                    else
                    {
                        ViewBag.InvalidUser = "******";
                    }
                }
            }
            else
            {
                return(RedirectToAction("Login", "Account"));
            }

            return(View());
        }
Пример #3
0
        public ActionResult Employee_Edit(tbl_employee_info employee)
        {
            if (Session["User_Id"] != null)
            {
                using (jugglecontext dbcon = new jugglecontext())
                {
                    try
                    {
                        string            multipleattribute = Request.Form["attribute_id_multiple"].ToString();
                        string            multipleservice   = Request.Form["emp_qualifiedservicetypes_multiple"].ToString();
                        tbl_employee_info empl = new tbl_employee_info();
                        empl.emp_id                    = employee.emp_id;
                        empl.emp_firstname             = employee.emp_firstname;
                        empl.emp_lastname              = employee.emp_lastname;
                        empl.emp_qualifiedservicetypes = multipleservice;
                        empl.user_id                   = employee.user_id;
                        empl.created_date              = employee.created_date;
                        empl.emp_code                  = autogenerateid();
                        empl.updated_date              = DateTime.Now;
                        empl.emp_contactinfo           = employee.emp_contactinfo;
                        empl.attribute_id              = multipleattribute;
                        empl.emp_transportion          = employee.emp_transportion;
                        empl.emp_googlecalendarID      = employee.emp_googlecalendarID;
                        empl.emp_note                  = employee.emp_note;
                        empl.emp_password              = dbcon.Encrypt(employee.emp_password);

                        dbcon.Entry(empl).State = System.Data.Entity.EntityState.Modified;
                        dbcon.SaveChanges();
                        return(RedirectToAction("Employee", "Employee"));
                    }
                    catch (DbEntityValidationException ex)
                    {
                        foreach (var entityValidationErrors in ex.EntityValidationErrors)
                        {
                            foreach (var validationError in entityValidationErrors.ValidationErrors)
                            {
                                Response.Write("Property: " + validationError.PropertyName + " Error: " + validationError.ErrorMessage);
                            }
                        }
                    }
                }
            }
            else
            {
                return(RedirectToAction("Login", "Account"));
            }
            return(View());
        }
Пример #4
0
        public ActionResult Create_Employee(tbl_employee_info employee)
        {
            using (jugglecontext dbcon = new jugglecontext())
            {
                try
                {
                    string            multipleattribute = Request.Form["attribute_id_multiple"].ToString();
                    string            multipleService   = Request.Form["emp_qualifiedservicetypes_multiple"].ToString();
                    var               getButton         = HttpContext.Request.Form["Create"];
                    tbl_employee_info empl = new tbl_employee_info();
                    empl.emp_firstname             = employee.emp_firstname.Trim();
                    empl.emp_lastname              = employee.emp_lastname.Trim();
                    empl.emp_contactinfo           = employee.emp_contactinfo.Trim();
                    empl.emp_qualifiedservicetypes = multipleService;
                    empl.created_date              = DateTime.Now;
                    empl.user_id              = Convert.ToInt32(Session["User_Id"]);
                    empl.emp_code             = autogenerateid();
                    empl.attribute_id         = multipleattribute;
                    empl.emp_googlecalendarID = employee.emp_googlecalendarID;
                    empl.emp_note             = employee.emp_note;
                    empl.emp_transportion     = employee.emp_transportion;
                    empl.emp_password         = dbcon.Encrypt(employee.emp_password);
                    dbcon.tbl_employee_info.Add(empl);
                    dbcon.SaveChanges();
                    return(RedirectToAction("Employee", "Employee"));
                }
                catch (DbEntityValidationException ex)
                {
                    foreach (var entityValidationErrors in ex.EntityValidationErrors)
                    {
                        foreach (var validationError in entityValidationErrors.ValidationErrors)
                        {
                            Response.Write("Property: " + validationError.PropertyName + " Error: " + validationError.ErrorMessage);
                        }
                    }

                    return(View(employee));
                }
            }
        }
Пример #5
0
        public ActionResult Login(tbl_user use_acc)
        {
            try
            {
                if (!string.IsNullOrEmpty(use_acc.username) && !string.IsNullOrEmpty(use_acc.password))
                {
                    var btnType = Request.Form["Login"];

                    if (btnType == "Login")
                    {
                        var u_Id      = "";
                        var u_Name    = "";
                        var u_Roll_Id = "";

                        using (jugglecontext dbcon = new jugglecontext())
                        {
                            if (use_acc.username == null || string.IsNullOrEmpty(use_acc.username))
                            {
                                ModelState.AddModelError("", "User Name is Required.");
                            }
                            else if (use_acc.password == null || string.IsNullOrEmpty(use_acc.password))
                            {
                                ModelState.AddModelError("", "Password is Required.");
                            }
                            else
                            {
                                var pass  = dbcon.Encrypt(use_acc.password);
                                var role1 = RoleType.Administrator.GetHashCode();

                                var getadministrator = dbcon.tbl_user.Where(administrator => administrator.role_id == role1).SingleOrDefault(u => u.username == use_acc.username && (u.password) == pass);
                                // var getadministrator = dbcon.tbl_user.Where(administrator => administrator.role_id == 4).SingleOrDefault(u => u.username == user.Username && (u.password) == user.Password);

                                if (getadministrator != null)
                                {
                                    Session["User_Id"]      = getadministrator.user_id.ToString();
                                    Session["profile_pict"] = getadministrator.profile_pict.ToString();
                                    Session["User_Name"]    = getadministrator.username.ToString();
                                    Session["firstname"]    = getadministrator.firstName.ToString();
                                    Session["User_Roll_Id"] = getadministrator.role_id.ToString();

                                    u_Id      = getadministrator.user_id.ToString();
                                    u_Name    = getadministrator.username.ToString();
                                    u_Roll_Id = getadministrator.role_id.ToString();

                                    return(RedirectToAction("ManageSupervisors", "Supervisors"));
                                }
                                else
                                {
                                    var role2         = RoleType.Supervisors.GetHashCode();
                                    var getSupervisor = dbcon.tbl_user.Where(Supervisor => Supervisor.role_id == role2 && Supervisor.status == 1).SingleOrDefault(u => u.username == use_acc.username && (u.password) == pass);
                                    if (getSupervisor != null)
                                    {
                                        Session["User_Id"]      = getSupervisor.user_id.ToString();
                                        Session["User_Name"]    = getSupervisor.username.ToString();
                                        Session["firstname"]    = getSupervisor.firstName.ToString();
                                        Session["profile_pict"] = getSupervisor.profile_pict.ToString();
                                        Session["User_Roll_Id"] = getSupervisor.role_id.ToString();
                                        try
                                        {
                                            Session["timezone"] = getSupervisor.timezoneid.ToString();
                                        }
                                        catch
                                        {
                                            Session["timezone"] = "Central Standard Time";
                                        }

                                        HttpCookie cookie = new HttpCookie("Timezone");
                                        cookie.Value = getSupervisor.timezoneid.ToString();
                                        this.ControllerContext.HttpContext.Response.Cookies.Add(cookie);

                                        AccountCookies.Value = "Testing";
                                        this.ControllerContext.HttpContext.Response.Cookies.Add(AccountCookies);
                                        AccountCookies.Expires = DateTime.Now.AddHours(1);

                                        u_Id      = getSupervisor.user_id.ToString();
                                        u_Name    = getSupervisor.username.ToString();
                                        u_Roll_Id = getSupervisor.role_id.ToString();

                                        return(RedirectToAction("Employee", "Employee"));
                                    }
                                    else
                                    {
                                        var role3   = RoleType.Workers.GetHashCode();
                                        var getuser = dbcon.tbl_user.Where(userlogin => userlogin.role_id == role3 && userlogin.status == 1).SingleOrDefault(u => u.username == use_acc.username && (u.password) == pass);
                                        if (getuser != null)
                                        {
                                            Session["User_Id"]      = getuser.user_id.ToString();
                                            Session["User_Name"]    = getuser.username.ToString();
                                            Session["firstname"]    = getuser.firstName.ToString();
                                            Session["profile_pict"] = getuser.profile_pict.ToString();
                                            Session["User_Roll_Id"] = getuser.role_id.ToString();
                                            u_Id      = getuser.user_id.ToString();
                                            u_Name    = getuser.username.ToString();
                                            u_Roll_Id = getuser.role_id.ToString();
                                            return(RedirectToAction("Client", "Client"));
                                        }
                                        else
                                        {
                                            ModelState.AddModelError("", "Invalid username or password !");
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
                else
                {
                    ModelState.AddModelError("", "Usename and Password Required !");
                }
            }
            catch (DbEntityValidationException ex)
            {
                foreach (var entityValidationErrors in ex.EntityValidationErrors)
                {
                    foreach (var validationError in entityValidationErrors.ValidationErrors)
                    {
                        Response.Write("Property: " + validationError.PropertyName + " Error: " + validationError.ErrorMessage);
                    }
                }
            }
            //ModelState.Clear();
            return(View());
        }
Пример #6
0
        public ActionResult Create_Supervisor(tbl_user user)
        {
            var autopassword = "";

            if (Session["User_Id"] != null)
            {
                using (jugglecontext dbcon = new jugglecontext())
                {
                    try
                    {
                        var getButton = HttpContext.Request.Form["Save"];
                        if (getButton == "Save")
                        {
                            {
                                int getstatusID = Convert.ToInt32(Request.Form["Status_hidden"]);
                                if (getstatusID == 0)
                                {
                                    getstatusID = 1;
                                }

                                var status = from p in dbcon.tbl_status
                                             select new { p.status_id, p.status };

                                var statusname = status.ToList().Select(c => new SelectListItem
                                {
                                    Text  = c.status.ToString(),
                                    Value = c.status_id.ToString(),
                                }).ToList();

                                ViewBag.status = statusname;
                                var      userId = Convert.ToInt32(Session["User_Id"]);
                                tbl_user tblusr = new tbl_user();
                                tblusr.firstName     = user.firstName.Trim();
                                tblusr.lastName      = user.lastName.Trim();
                                tblusr.address       = user.address;
                                tblusr.phoneno       = user.phoneno.Trim();
                                tblusr.email         = user.email.Trim();
                                tblusr.username      = user.username.Trim();
                                autopassword         = dbcon.GeneratePassword(6);
                                tblusr.password      = dbcon.Encrypt(autopassword.Trim());
                                tblusr.supervisor_id = userId;
                                tblusr.created_date  = DateTime.Now;

                                tblusr.timezoneid       = "Central Standard Time";
                                tblusr.status           = user.status;
                                tblusr.role_id          = 2;
                                tblusr.user_id          = 0;
                                Session["firstname"]    = user.firstName;
                                Session["profile_pict"] = user.profile_pict;
                                if (Request.Files.Count > 0)
                                {
                                    var file = Request.Files[0];

                                    if (file != null && file.ContentLength > 0)
                                    {
                                        var fileName = Path.GetFileName(file.FileName);
                                        var path     = Path.Combine(Server.MapPath("~/Profile_Picture/"), fileName);
                                        file.SaveAs(path);
                                        tblusr.profile_pict = fileName;
                                    }
                                    else
                                    {
                                        tblusr.profile_pict = "Noimage.png";
                                    }
                                }

                                dbcon.tbl_user.Add(tblusr);
                                dbcon.SaveChanges();

                                string Body = "Hello, \nYour Username: "******" \nPassword: "******" \n\n for login in Juggle Click this Link to login  \n " + dbcon.redirectUrl() + "";
                                dbcon.SendMail(tblusr.email, "Login Credntials for Juggle", Body, tblusr.username, autopassword);

                                return(RedirectToAction("ManageSupervisors", "Supervisors"));
                            }
                        }
                        else
                        {
                        }
                    }
                    catch (DbEntityValidationException ex)
                    {
                        foreach (var entityValidationErrors in ex.EntityValidationErrors)
                        {
                            foreach (var validationError in entityValidationErrors.ValidationErrors)
                            {
                                Response.Write("Property: " + validationError.PropertyName + " Error: " + validationError.ErrorMessage);
                            }
                        }
                        return(View(user));
                    }
                }
            }
            else
            {
                return(RedirectToAction("Login", "Account"));
            }
            return(View(user));
        }