/// <summary>
        /// This action retrieves the schedule edit page
        /// </summary>
        /// <param name="id">Schedule id</param>
        /// <returns>Edit view</returns>
        // GET: ProjectSchedule/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            ProjectSchedule projectSchedule = db.ProjectSchedules.Find(id);

            if (projectSchedule == null)
            {
                return(HttpNotFound());
            }

            var model = new ProjectScheduleViewModel
            {
                ScheduleId     = projectSchedule.ScheduleId,
                ScheduleDate   = projectSchedule.Date,
                StartTime      = projectSchedule.StartTime,
                EndTime        = projectSchedule.EndTime,
                EventProjectId = projectSchedule.EventProjectId
            };

            return(View(model));
        }
        private List <Dictionary <DateTime, decimal> > FetchStaffProjectMonthlyHourRows(Dictionary <DateTime, decimal> monthlyHours, IQueryable <ProjectSchedule> staffProjectSchedules)
        {
            List <Dictionary <DateTime, decimal> > staffProjectMonthyHourRows = new List <Dictionary <DateTime, decimal> >();
            var query = staffProjectSchedules
                        .Include(p => p.StaffMember)
                        .Include(p => p.Project)
                        .AsEnumerable();

            foreach (var ps in
                     query.GroupBy(p => p.ProjectId))
            {
                ProjectSchedule projectSchedule = ps.First(); // usually only one project schedule applied between staff and project
                StaffMember     staff           = projectSchedule.StaffMember;
                Dictionary <DateTime, decimal> trackedHoursByMonth = FetchTrackedHoursByMonth(projectSchedule);

                Dictionary <DateTime, decimal> forecastedHoursByMonth = ForecastHoursByMonthLinear(projectSchedule, trackedHoursByMonth, monthlyHours);

                Dictionary <DateTime, decimal> projectHoursByMonth = CalculateSumOfAllMonthlyHourRows(new List <Dictionary <DateTime, decimal> >()
                {
                    trackedHoursByMonth,
                    forecastedHoursByMonth
                });

                staffProjectMonthyHourRows.Add(projectHoursByMonth);
            }
            return(staffProjectMonthyHourRows);
        }
Esempio n. 3
0
        //sccsc



        //____________________________________________________________________________________________
        public JsonResult SaveProjectSchedule(int ProjectId, string Version, string StartDate, string EndDate, string CreatedDate, string CreatedBy)
        {
            var result = new jsonMessage();

            try
            {
                //define the model
                ProjectSchedule newProjectSchedule = new ProjectSchedule();
                newProjectSchedule.ProjectId   = ProjectId;
                newProjectSchedule.Version     = Version;
                newProjectSchedule.StartDate   = Convert.ToDateTime(StartDate);
                newProjectSchedule.EndDate     = Convert.ToDateTime(EndDate);
                newProjectSchedule.CreatedDate = Convert.ToDateTime(CreatedDate);
                newProjectSchedule.CreatedBy   = CreatedBy;
                newProjectSchedule.IsActive    = true;



                //for insert recored..
                db.ProjectSchedules.Add(newProjectSchedule);
                result.Message = "Data Schedule Project berhasil disimpan...";
                result.Status  = true;

                db.SaveChanges();
            }
            catch (Exception ex)
            {
                //ErrorLogers.ErrorLog(ex);
                result.Message = "Permintaan Anda tidak bisa diproses. Coba lagi nanti.";
                result.Status  = false;
            }
            return(Json(result, JsonRequestBehavior.AllowGet));
        }
        public async Task OnGetAsync()
        {
            ProjectSchedule = await _context.ProjectSchedule
                              .OrderByDescending(p => p.ProjectId)
                              .Include(p => p.Project)
                              .Include(p => p.StaffMember).ToListAsync();

            ProjectScheduleGroups = ProjectSchedule.GroupBy(p => p.ProjectId);
        }
        public ActionResult DeleteConfirmed(int id, ProjectScheduleViewModel model)
        {
            //var projectSchedule = db.ProjectSchedules.Find(model.ScheduleId);

            ProjectSchedule projectSchedule = db.ProjectSchedules.Find(id);

            db.ProjectSchedules.Remove(projectSchedule);
            db.SaveChanges();
            return(RedirectToAction("DetailsMaster", "EventProject", new { id = model.EventProjectId }));
            //return RedirectToAction("DetailsMaster", "EventProject", new { projectId = model.EventProjectId });
        }
        public ActionResult Edit(ProjectScheduleViewModel model)
        {
            if (ModelState.IsValid)
            {
                ProjectSchedule projectSchedule = Mapper.Map <ProjectScheduleViewModel, ProjectSchedule>(model);
                db.Entry(projectSchedule).State = EntityState.Modified;
                db.SaveChanges();

                return(RedirectToAction("Index"));
            }

            return(View(model));
        }
        public async Task <ProjectScheduleResponse> SaveAsync(ProjectSchedule projectSchedule)
        {
            try
            {
                await _projectScheduleRepository.AddAsync(projectSchedule);

                return(new ProjectScheduleResponse(projectSchedule));
            }
            catch (Exception ex)
            {
                return(new ProjectScheduleResponse($"An error ocurred while saving the ProjectSchedule: {ex.Message}"));
            }
        }
Esempio n. 8
0
        public async Task <IActionResult> EvaluateProjectSchedule(ProjectSchedule projectSchedule)
        {
            var result = await _context.ProjectSchedules.FindAsync(projectSchedule.Id);

            await _context.Entry(result).Reference("Project").LoadAsync();

            if (result.Project.LecturerId == getCurrentLecturerId())
            {
                result.Rating  = projectSchedule.Rating;
                result.Comment = projectSchedule.Comment;
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Details), new { id = result.ProjectId }));
            }
            return(BadRequest());
        }
        /// <summary>
        /// Performs a daily linear interpolation based on the remaining number of hours
        /// Could add a type that adds different types of search
        /// </summary>
        /// <param name="projectSchedule">The project schedule from which to gather the end date</param>
        /// <param name="trackedHoursByMonth">A dictionary containing the total number of hours worked on this project by month</param>
        /// <param name="monthlyHours">Reference for the start and end months</param>
        /// <returns>Months with the number of forecasted hours to add.</returns>
        private Dictionary <DateTime, decimal> ForecastHoursByMonthLinear(ProjectSchedule projectSchedule, Dictionary <DateTime, decimal> trackedHoursByMonth, Dictionary <DateTime, decimal> monthlyHours)
        {
            // clone the monthly hours
            Dictionary <DateTime, decimal> forecastHoursByMonth = InitializeEmptyMonthlyHours(monthlyHours);

            DateTime startForecastDate = FirstOfMonth(trackedHoursByMonth.Keys.Max()).AddMonths(1);
            DateTime endProjectDate    = FirstOfMonth(projectSchedule.Project.ProjectEndDate).AddMonths(1).AddDays(-1); // need to subtract one day to avoid the due date.
            decimal  delta             = (endProjectDate - startForecastDate).Days;

            if (delta <= 0)
            {
                return(forecastHoursByMonth);            // project is already done!
            }
            decimal totalTrackedHours   = trackedHoursByMonth.Values.Sum();
            decimal hoursPerDay         = 7.5M;
            decimal totalScheduledHours = projectSchedule.Days * hoursPerDay;
            decimal remainingWork       = totalScheduledHours - totalTrackedHours;

            if (remainingWork <= 0M)
            {
                return(forecastHoursByMonth);                     // project is already overdue!
            }
            decimal  dailyWork  = remainingWork / delta;
            DateTime currentDay = startForecastDate;
            int      i          = 0;

            while (i <= delta)
            {
                // could include logic to avoid weeknds etc.

                // add the little bit to the monthly value
                DateTime key = FirstOfMonth(currentDay);
                if (forecastHoursByMonth.ContainsKey(key))
                {
                    forecastHoursByMonth[key] = forecastHoursByMonth[key] + dailyWork;
                }
                else
                {
                    break;
                }

                currentDay = currentDay.AddDays(1);
                i++;
            }

            return(forecastHoursByMonth);
        }
Esempio n. 10
0
        public async Task <IActionResult> EditProjectSchedule(ProjectSchedule projectSchedule)
        {
            var result = await _context.ProjectSchedules.FindAsync(projectSchedule.Id);

            await _context.Entry(result).Reference("Project").LoadAsync();

            if (result.Project.LecturerId == getCurrentLecturerId())
            {
                result.Name        = projectSchedule.Name;
                result.Description = projectSchedule.Description;
                result.ExpiredDate = projectSchedule.ExpiredDate;
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Details), new { id = result.ProjectId }));
            }
            return(BadRequest());
        }
Esempio n. 11
0
        public async Task <IActionResult> OnPostAsync(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            ProjectSchedule = await _context.ProjectSchedule.FindAsync(id);

            if (ProjectSchedule != null)
            {
                // _context.ProjectSchedule.Remove(ProjectSchedule);
                await _context.SaveChangesAsync();
            }

            return(RedirectToPage("./Index"));
        }
Esempio n. 12
0
        public async Task <IActionResult> OnGetAsync(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            ProjectSchedule = await _context.ProjectSchedule
                              .Include(p => p.Project)
                              .Include(p => p.StaffMember).FirstOrDefaultAsync(m => m.ProjectScheduleId == id);

            if (ProjectSchedule == null)
            {
                return(NotFound());
            }
            return(Page());
        }
        /// <summary>
        /// Return the sums of each month for this project schedule
        /// </summary>
        /// <param name="projectSchedule"></param>
        /// <returns>A dictionary containing the months and the total hours worked in those months.</returns>
        private Dictionary <DateTime, decimal> FetchTrackedHoursByMonth(ProjectSchedule projectSchedule)
        {
            Dictionary <DateTime, decimal> trackedHoursByMonth = new Dictionary <DateTime, decimal>();
            var trackingLogByMonth = _context.TrackingLog
                                     .Where(t => t.StaffMemberId == projectSchedule.StaffMemberId)
                                     .Where(t => t.ProjectId == projectSchedule.ProjectId)
                                     .AsEnumerable()
                                     .GroupBy(t => FirstOfMonth(t.Date));

            foreach (var month in trackingLogByMonth)
            {
                trackedHoursByMonth.Add(
                    month.Key,
                    month.Sum(m => m.Hours)
                    );
            }
            return(trackedHoursByMonth);
        }
        public async Task <IActionResult> OnGetAsync(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            ProjectSchedule = await _context.ProjectSchedule
                              .Include(p => p.Project)
                              .Include(p => p.StaffMember).FirstOrDefaultAsync(m => m.ProjectScheduleId == id);

            if (ProjectSchedule == null)
            {
                return(NotFound());
            }
            ViewData["ProjectId"]     = new SelectList(_context.Project, "ProjectId", "ProjectId");
            ViewData["StaffMemberId"] = new SelectList(_context.StaffMember, "StaffMemberId", "StaffMemberId");
            return(Page());
        }
        public ActionResult ProjectSchedulesPartial(ProjectScheduleViewModel model)
        {
            if (ModelState.IsValid)
            {
                var project = db.EventProjects.Find(model.EventProjectId);

                if (project == null)
                {
                    return(HttpNotFound());
                }

                var schedule = new ProjectSchedule
                {
                    Date           = model.ScheduleDate,
                    StartTime      = model.StartTime,
                    EndTime        = model.EndTime,
                    EventProjectId = model.EventProjectId
                };

                //// Validating the date of birth
                //if (model.EndTime < model.StartTime)
                //{
                //    ModelState.AddModelError("EndTime", "The ending time of an event cannot be before the starting time.");
                //    ModelState.AddModelError(String.Empty, "Issue with the ending time");

                //    return View(model);
                //}
                //else if (model.StartTime < DateTime.Now.TimeOfDay)
                //{
                //    ModelState.AddModelError("StartTime", "The starting time of an event cannot be before this time.");
                //    ModelState.AddModelError(String.Empty, "Issue with the starting time");

                //    return View(model);
                //}

                db.ProjectSchedules.Add(schedule);
                db.SaveChanges();
            }

            return(PartialView(model));
        }
        public async Task <ProjectScheduleResponse> UpdateAsync(int id, ProjectSchedule projectSchedule)
        {
            var existingProjectSchedule = await _projectScheduleRepository.FindById(id);

            if (existingProjectSchedule == null)
            {
                return(new ProjectScheduleResponse("ProjectSchedule not found"));
            }

            existingProjectSchedule.Name = projectSchedule.Name;

            try
            {
                _projectScheduleRepository.Update(existingProjectSchedule);

                return(new ProjectScheduleResponse(existingProjectSchedule));
            }
            catch (Exception ex)
            {
                return(new ProjectScheduleResponse($"An error ocurred while updating ProjectSchedule: {ex.Message}"));
            }
        }
Esempio n. 17
0
 public void Remove(ProjectSchedule projectSchedule)
 {
     _context.ProjectsSchedules.Remove(projectSchedule);
 }
Esempio n. 18
0
 public void Update(ProjectSchedule projectSchedule)
 {
     _context.ProjectsSchedules.Update(projectSchedule);
 }
Esempio n. 19
0
 public async Task AddAsync(ProjectSchedule projectSchedule)
 {
     await _context.ProjectsSchedules.AddAsync(projectSchedule);
 }
 public ActionResult EditProjSched(ProjectSchedule projsched)
 {
     if (ModelState.IsValid)
     {
         db.Entry(projsched).State = EntityState.Modified;
         db.SaveChanges();
         return RedirectToAction("Index");
     }
     return View(projsched);
 }
        public ActionResult CreateProjSched(ProjectSchedule projsched)
        {
            ModelState.Clear();
            if (ModelState.IsValid)
            {
                db.ProjectSchedules.Add(projsched);
                db.SaveChanges();
                return RedirectToAction("Index");
            }

            return View(projsched);
        }