public ActionResult Edit([Bind(Include = "ProjectID, Name, SuperiorID, Start, Finish")] Projects project)
        {
            if (Session["EmployeeID"] == null)
            {
                Session["PleaseLogin"] = true;
                return(RedirectToAction("", "Home"));
            }
            var permutil = new PermissionUtil();

            if (permutil.IsAdministrator((int)Session["JobPosition"]))
            {
                var projToEdit = ctx.Projects.Find(project.ProjectID);
                if (projToEdit == null)
                {
                    return(HttpNotFound("Projekt o podanym ID nie istnieje!"));
                }

                projToEdit.Name       = project.Name;
                projToEdit.SuperiorID = project.SuperiorID;
                projToEdit.Start      = project.Start;
                projToEdit.Finish     = project.Finish;

                if (project.Finish != null && project.Start > project.Finish)
                {
                    ModelState.AddModelError("Start", "Data rozpoczęcia jest późniejsza niż data zakończenia projektu.");
                    PopulateSuperiorsList();
                    return(View(projToEdit));
                }

                ctx.Entry(projToEdit).State = EntityState.Modified;
                ctx.SaveChanges();
                return(RedirectToAction("Overview", "Project"));
            }
            return(RedirectToAction("Overview", "Project"));
        }
Example #2
0
 public ActionResult Edit([Bind(Include = "EMail, Name, Surname, Telephone")] Employees empl)
 {
     if (Session["EmployeeID"] != null)
     {
         if (empl.EMail != null && empl.Name != null && empl.Surname != null && empl.Telephone != null)
         {
             using (TimesheetDBEntities ctx = new TimesheetDBEntities())
             {
                 int    employeeID = (int)Session["EmployeeID"];
                 var    foundEmpl  = ctx.Employees.Where(x => x.EmployeeID == employeeID).FirstOrDefault();
                 string typedEmail = empl.EMail;
                 if (typedEmail == ctx.Employees.Where(x => x.EMail == typedEmail && x.EmployeeID != employeeID).Select(x => x.EMail).FirstOrDefault())
                 {
                     ViewData["Message"] = "Podany e-mail jest już zajęty";
                 }
                 else
                 {
                     foundEmpl.Name             = empl.Name;
                     foundEmpl.Surname          = empl.Surname;
                     foundEmpl.Telephone        = empl.Telephone;
                     foundEmpl.EMail            = empl.EMail;
                     ctx.Entry(foundEmpl).State = EntityState.Modified;
                     ctx.SaveChanges();
                     ViewData["Message"] = "OK";
                 }
             }
         }
         return(View(empl));
     }
     return(RedirectToAction("", "Home"));
 }
Example #3
0
        public ActionResult Unlock(int userId)
        {
            if (Session["EmployeeID"] == null)
            {
                Session["PleaseLogin"] = true;
                return(RedirectToAction("", "Home"));
            }
            CheckUserPermission();
            var empl = ctx.Employees.Find(userId);

            if (empl != null)
            {
                empl.LoginNo          = 0;
                ctx.Entry(empl).State = EntityState.Modified;
                ctx.SaveChanges();
            }
            return(RedirectToAction("", "User"));
        }
Example #4
0
        public ActionResult ChangePassword(string[] pass) //table of passwords
        {
            if (pass[0] != "" && pass[1] != "" && pass[2] != "")
            {
                if (Session["EmployeeID"] != null)
                {
                    using (TimesheetDBEntities ctx = new TimesheetDBEntities())
                    {
                        int employeeID    = (int)Session["EmployeeID"];
                        var foundEmployee = ctx.Employees.Where(x => x.EmployeeID == employeeID).FirstOrDefault(); //employee

                        byte[] oldPassword = Encoding.Default.GetBytes(pass[0]);                                   //employee old pass
                        using (var sha256 = SHA256.Create())
                        {
                            byte[] hashOldPass    = sha256.ComputeHash(oldPassword);                               //256-bits employee pass
                            string hashOldPassHex = BitConverter.ToString(hashOldPass).Replace("-", string.Empty); //64 chars hash pass

                            if (hashOldPassHex == foundEmployee.Password)                                          //user typed proper old pass
                            {
                                if (pass[1] == pass[2])                                                            //user typed twice the same new pass
                                {
                                    byte[] newPass        = Encoding.Default.GetBytes(pass[1]);
                                    byte[] hashNewPass    = sha256.ComputeHash(newPass);
                                    string hashNewPassHex = BitConverter.ToString(hashNewPass).Replace("-", string.Empty);

                                    foundEmployee.Password         = hashNewPassHex;
                                    ctx.Entry(foundEmployee).State = EntityState.Modified;
                                    ctx.SaveChanges();
                                    ViewData["Message"] = "OK";
                                }
                                else
                                {
                                    ViewData["Message"] = "Podane hasła nie zgadzają się!";
                                    //ModelState.AddModelError("", "Podane hasła nie zgadzają się!");
                                }
                            }
                            else
                            {
                                ViewData["Message"] = "Podane stare hasło jest nieprawidłowe!";
                                //ModelState.AddModelError("", "Podane stare hasło jest nieprawidłowe!");
                            }
                        }
                    }
                }
                else
                {
                    return(RedirectToAction("", "Home"));
                }
            }
            else
            {
                ViewData["Message"] = "Przynajmniej jedno z wymaganych pól jest nieuzupełnione!";
                //ModelState.AddModelError("", "Przynajmniej jedno z wymaganych pól jest nieuzupełnione!");
            }
            return(View());
        }
Example #5
0
        public ActionResult Login(string email, string passwd)
        {
            using (TimesheetDBEntities ctx = new TimesheetDBEntities())
            {
                byte[] pass = Encoding.Default.GetBytes(passwd); //employee pass in bytes
                using (var sha256 = SHA256.Create())
                {
                    byte[] hashPass    = sha256.ComputeHash(pass);                                   //256-bits employee pass
                    string hashPassHex = BitConverter.ToString(hashPass).Replace("-", string.Empty); //64 chars hash pass

                    //get login and pass from DB
                    var empl = ctx.Employees.Where(e => e.EMail == email).FirstOrDefault();
                    if (empl != null)
                    {
                        if (empl.Password == hashPassHex) //user typed proper data
                        {
                            if (empl.LoginNo < incorrectPasswordNo)
                            {
                                Session["EmployeeID"]  = empl.EmployeeID;
                                Session["JobPosition"] = empl.JobPositionID;
                                Session["NameSurname"] = empl.Name.ToString() + " " + empl.Surname.ToString();
                                empl.LastLogin         = DateTime.Now;
                                empl.LoginNo           = 0; // 0 the counter
                                Session["PleaseLogin"] = null;
                                Session["Login"]       = null;
                            }
                            else
                            {
                                Session["Login"] = "******";
                                return(RedirectToAction("", "Home"));
                            }
                        }
                        else //user typed incorrect password
                        {
                            if (empl.LoginNo < incorrectPasswordNo)
                            {
                                empl.LoginNo += 1;//add one because of failed login attempt
                            }
                            else
                            {
                                Session["Login"] = "******";
                                return(RedirectToAction("", "Home"));
                            }
                        }
                        ctx.Entry(empl).State = EntityState.Modified;
                        ctx.SaveChanges();
                    }
                }
            }

            return(RedirectToAction("", "Home"));
        }
        public ActionResult SaveTimesheet(string[] data)
        {
            //projectName is the identyfier of the project!
            //string -> int
            bool properData = false; //data null or proper condition

            if (Session["EmployeeID"] != null)
            {
                if (data == null)
                {
                    properData = true;
                }
                else if (data.Length % 10 == 0)
                {
                    properData = true;
                }
                if (Session["timesheetID"] != null && properData == true)
                {
                    List <long> taskIDFromTimesheet = new List <long>();
                    //int projectID = Int32.Parse(Session["projectID"].ToString());
                    int employeeID  = Int32.Parse(Session["EmployeeID"].ToString());
                    int timesheetID = Int32.Parse(Session["TimesheetID"].ToString());
                    using (TimesheetDBEntities ctx = new TimesheetDBEntities())
                    {
                        //var projectMemberID = ctx.ProjectMembers.Where(x => x.ProjectID == projectID && x.EmployeeID == employeeID).Select(x => x.ProjectMemberID).FirstOrDefault();
                        // if (projectMemberID != null)
                        //{
                        //where start & finish && dateTimeNow beetween
                        var dateTimeNow = DateTime.Now.Date;
                        //var timesheetID = ctx.Timesheets.Where(x => x.ProjectMemberID == projectMemberID && x.TimesheetStateID == 1).Select(x => x.TimesheetID).FirstOrDefault();
                        if (timesheetID > 0)     //timesheetID
                        {
                            int   taskID = 0;
                            Tasks task;
                            var   tasks = ctx.Tasks.Where(x => x.TimesheetID == timesheetID);
                            //can be no data
                            if (data != null)
                            {
                                for (int i = 0; i < data.Length; i += 10)
                                {
                                    taskID = Int32.Parse(data[i]);
                                    taskIDFromTimesheet.Add(taskID);
                                    if (taskID == 0) //new task
                                    {
                                        task = new Tasks();

                                        task.TimesheetID    = timesheetID;
                                        task.TaskName       = data[i + 1];
                                        task.MondayHours    = Decimal.Parse(data[i + 2]);
                                        task.TuesdayHours   = Decimal.Parse(data[i + 3]);
                                        task.WednesdayHours = Decimal.Parse(data[i + 4]);
                                        task.ThursdayHours  = Decimal.Parse(data[i + 5]);
                                        task.FridayHours    = Decimal.Parse(data[i + 6]);
                                        task.SaturdayHours  = Decimal.Parse(data[i + 7]);
                                        task.SundayHours    = Decimal.Parse(data[i + 8]);
                                        task.Comment        = data[i + 9];
                                        task.LastEditedBy   = employeeID;
                                        task.LastEditDate   = DateTime.Now;
                                        task.CreatedBy      = employeeID;
                                        task.CreationDate   = DateTime.Now;
                                        ctx.Tasks.Add(task);
                                    }
                                    else //existing task
                                    {
                                        task = tasks.Where(x => x.TaskID == taskID).FirstOrDefault();//ctx.Tasks.Where(x => x.TaskID == taskID).FirstOrDefault();

                                        task.TaskName       = data[i + 1];
                                        task.MondayHours    = Decimal.Parse(data[i + 2]);
                                        task.TuesdayHours   = Decimal.Parse(data[i + 3]);
                                        task.WednesdayHours = Decimal.Parse(data[i + 4]);
                                        task.ThursdayHours  = Decimal.Parse(data[i + 5]);
                                        task.FridayHours    = Decimal.Parse(data[i + 6]);
                                        task.SaturdayHours  = Decimal.Parse(data[i + 7]);
                                        task.SundayHours    = Decimal.Parse(data[i + 8]);
                                        task.Comment        = data[i + 9];
                                        task.LastEditedBy   = employeeID;
                                        task.LastEditDate   = DateTime.Now;

                                        ctx.Entry(task).State = EntityState.Modified;
                                    }
                                }
                            }
                            //Remove from db tasks which users has deleted
                            //tasks -> list of tasks from DB
                            //taskIDFromTimesheet
                            foreach (var item in tasks)
                            {
                                if (!taskIDFromTimesheet.Contains(item.TaskID))
                                {
                                    ctx.Entry(item).State = EntityState.Deleted;
                                }
                            }
                        }
                        //}

                        ctx.SaveChanges();
                        TempData["SaveChanges"] = "OK";
                        int timesheetStateID = ctx.Timesheets.Where(x => x.TimesheetID == timesheetID).Select(x => x.TimesheetStateID).FirstOrDefault();
                        if (timesheetStateID > 0)
                        {
                            if (timesheetStateID == 1)
                            {
                                return(RedirectToAction("Current", "Timesheet"));
                            }
                            else if (timesheetStateID == 5)
                            {
                                return(RedirectToAction("Disapproved", "Timesheet"));
                            }
                        }
                    }
                }
            }
            return(RedirectToAction("", "Home"));
        }