Beispiel #1
0
        public ActionResult DeleteConfirmed(int id)
        {
            hoursworked hoursworked = db.hoursworkeds.Find(id);

            db.hoursworkeds.Remove(hoursworked);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Beispiel #2
0
        public ActionResult AddHourWorked(int entryDay)
        {
            var         emp     = UserManager.User.employeeID;
            hoursworked newHour = new hoursworked();

            newHour.currentDay  = (DayOfWeek)Enum.Parse(typeof(DayOfWeek), entryDay.ToString());
            newHour.ProjectList = GetGroupProjects(emp.ToString());
            return(PartialView("_hoursworkedrow", newHour));
        }
Beispiel #3
0
        public static hoursworked EntryExists(hoursworked entry)
        {
            var existsQuery = from hw in new CronusDatabaseEntities().hoursworkeds
                              where (hw.TimePeriod_employeeID.Equals(entry.TimePeriod_employeeID) && DbFunctions.TruncateTime(hw.date) == DbFunctions.TruncateTime(entry.date) && hw.Project_projectID == entry.Project_projectID && hw.Activity_activityID == entry.Activity_activityID)
                              select hw;

            if (existsQuery.Any())
            {
                return(existsQuery.First());
            }
            return(null);
        }
Beispiel #4
0
        public ActionResult AddLastWeekPartials(int entryDay, int projectID, int activityID)
        {
            var         emp        = UserManager.User.employeeID;
            var         getProject = from proj in db.projects where proj.projectID == projectID select proj;
            hoursworked myHour     = new hoursworked();

            myHour.project             = getProject.First();
            myHour.Project_projectID   = projectID;
            myHour.Activity_activityID = activityID;
            myHour.currentDay          = (DayOfWeek)Enum.Parse(typeof(DayOfWeek), entryDay.ToString());
            myHour.ProjectList         = GetGroupProjects(emp);
            return(PartialView("_hoursworkedrow", myHour));
        }
Beispiel #5
0
 public ActionResult Edit([Bind(Include = "entryID,hours,date,comments,TimePeriod_employeeID,TimePeriod_periodEndDate,Activity_activityID,Project_projectID")] hoursworked hoursworked)
 {
     if (ModelState.IsValid)
     {
         db.Entry(hoursworked).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.Activity_activityID   = new SelectList(db.activities, "activityID", "activityName", hoursworked.Activity_activityID);
     ViewBag.TimePeriod_employeeID = new SelectList(db.employeetimeperiods, "Employee_employeeID", "Employee_employeeID", hoursworked.TimePeriod_employeeID);
     ViewBag.Project_projectID     = new SelectList(db.projects, "projectID", "projectName", hoursworked.Project_projectID);
     return(View(hoursworked));
 }
Beispiel #6
0
 public void InsertOrUpdate(hoursworked hoursworked)
 {
     //if (hoursworked.hoursworkedID == default(int))
     if (Find(hoursworked.entryID) == null)
     {
         // New entity
         context.hoursworkeds.Add(hoursworked);
     }
     else
     {
         // Existing entity
         context.Entry(hoursworked).State = EntityState.Modified;
     }
 }
Beispiel #7
0
        // GET: HoursWorked/Details/5
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            hoursworked hoursworked = db.hoursworkeds.Find(id);

            if (hoursworked == null)
            {
                return(HttpNotFound());
            }
            return(View(hoursworked));
        }
Beispiel #8
0
        public ActionResult AddHours(hoursworked entry)
        {
            var result = db.hoursworkeds.Find(entry.entryID);

            if (result != null)
            {
                result.Project_projectID = entry.Project_projectID; result.Activity_activityID = entry.Activity_activityID;
                result.hours             = entry.hours; result.comments = entry.comments;
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }
            ViewBag.Activity_activityID   = new SelectList(db.activities, "activityID", "activityName");
            ViewBag.TimePeriod_employeeID = new SelectList(db.employeetimeperiods, "Employee_employeeID", "Employee_employeeID");
            ViewBag.Project_projectID     = new SelectList(db.projects, "projectID", "projectName");
            return(View());
        }
Beispiel #9
0
        // GET: HoursWorked/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            hoursworked hoursworked = db.hoursworkeds.Find(id);

            if (hoursworked == null)
            {
                return(HttpNotFound());
            }
            ViewBag.Activity_activityID   = new SelectList(db.activities, "activityID", "activityName", hoursworked.Activity_activityID);
            ViewBag.TimePeriod_employeeID = new SelectList(db.employeetimeperiods, "Employee_employeeID", "Employee_employeeID", hoursworked.TimePeriod_employeeID);
            ViewBag.Project_projectID     = new SelectList(db.projects, "projectID", "projectName", hoursworked.Project_projectID);
            return(View(hoursworked));
        }
Beispiel #10
0
        public ActionResult SubmitHours(HomeViewModel submittedHours, string submitButton)
        {
            var      emp       = UserManager.User.employeeID;
            DateTime AddToWeek = submittedHours.currentWeekEndDate.Date;
            // Check if timeperiod already exists
            // If not create it
            DateTime timePeriod = submittedHours.currentWeekEndDate.Date;

            if (db.timeperiods.Find(timePeriod) == null)
            {
                timeperiod newTimePeriod = new timeperiod();
                newTimePeriod.periodEndDate = timePeriod;
                new TimeperiodController().Create(newTimePeriod);
            }
            // Check if employee already has this timeperiod
            // If not create it
            var employeeTPexists = from tp in db.employeetimeperiods
                                   where tp.Employee_employeeID == emp && tp.TimePeriod_periodEndDate == timePeriod
                                   select tp;

            if (!employeeTPexists.Any())
            {
                employeetimeperiod etp = new employeetimeperiod();
                etp.Employee_employeeID = emp; etp.TimePeriod_periodEndDate = timePeriod;
                etp.isApproved          = false;
                new EmployeeTimeperiodsController().Create(etp);
            }
            foreach (var entry in submittedHours.HoursWorked)
            {
                if (entry.isDeleted)
                {
                    hoursworked deleteEntry = db.hoursworkeds.Find(entry.entryID);
                    if (deleteEntry != null)
                    {
                        new HoursWorkedController().DeleteConfirmed(deleteEntry.entryID);
                    }
                }
                else if (entry.hours > 0 && entry.Activity_activityID != 0 && entry.Project_projectID != 0)
                {
                    if (entry.entryID == 0)
                    {
                        // Check if the activity was already logged on the current date
                        // If it was, just add hours to the entry
                        // Otherwise, create a new entry
                        hoursworked newEntry      = new hoursworked();
                        DateTime    periodEndDate = AddToWeek;
                        newEntry.hours    = entry.hours; newEntry.Project_projectID = entry.Project_projectID; newEntry.Activity_activityID = entry.Activity_activityID; newEntry.date = ExtensionMethods.GetDateInWeek(periodEndDate, entry.currentDay);
                        newEntry.comments = entry.comments; newEntry.TimePeriod_employeeID = emp; newEntry.TimePeriod_periodEndDate = periodEndDate.Date;

                        if (ExtensionMethods.EntryExists(newEntry) == null)
                        {
                            new HoursWorkedController().Create(newEntry);
                        }
                        else
                        {
                            hoursworked existingEntry = ExtensionMethods.EntryExists(newEntry);
                            existingEntry.hours    += newEntry.hours;
                            existingEntry.comments += ", " + newEntry.comments;
                            new HoursWorkedController().AddHours(existingEntry);
                        }
                    }
                    // Updating already existing entry
                    else
                    {
                        // If we get to this point, entry is already saved to DB, and we're editing it
                        hoursworked existingEntry = db.hoursworkeds.First(hw => hw.entryID == entry.entryID);
                        existingEntry.Activity_activityID = entry.Activity_activityID; existingEntry.activity = entry.activity;
                        existingEntry.Project_projectID   = entry.Project_projectID; existingEntry.project = entry.project;
                        existingEntry.hours    = entry.hours;
                        existingEntry.comments = entry.comments;
                        existingEntry.date     = entry.date;
                        new HoursWorkedController().AddHours(existingEntry);
                    }
                }
            }
            if (submitButton == "Previous")
            {
                submittedHours.currentWeekEndDate = submittedHours.currentWeekEndDate.AddDays(-7);
            }
            else if (submitButton == "Next")
            {
                submittedHours.currentWeekEndDate = submittedHours.currentWeekEndDate.AddDays(7);
            }

            ModelState.Clear();
            HomeViewModel myModel = new HomeViewModel();

            myModel.currentWeekEndDate = submittedHours.currentWeekEndDate;
            var query = from hw in db.hoursworkeds
                        where hw.TimePeriod_employeeID == UserManager.User.employeeID && DbFunctions.TruncateTime(hw.TimePeriod_periodEndDate) == myModel.currentWeekEndDate.Date
                        select hw;

            myModel.HoursWorked = query.ToList();
            foreach (var hw in myModel.HoursWorked)
            {
                hw.currentDay = hw.date.DayOfWeek;
            }
            // If Timeperiod was already approved, set Viewbag isApproved to true
            var isApprovedQuery = from a in db.employeetimeperiods
                                  where a.Employee_employeeID == UserManager.User.employeeID && DbFunctions.TruncateTime(a.TimePeriod_periodEndDate) == myModel.currentWeekEndDate.Date
                                  select a;

            if (isApprovedQuery.Any())
            {
                myModel.isApproved = isApprovedQuery.First().isApproved;
            }
            // Get list of active projects that group is working on
            List <project> groupProjects = GetGroupProjects(emp.ToString());

            foreach (var hrworked in myModel.HoursWorked)
            {
                hrworked.ProjectList = groupProjects;
            }
            myModel.ProjectList = groupProjects;

            return(View("Index", myModel));
        }