Esempio n. 1
0
        public ActionResult AddWorkTime(int taskId)
        {
            var manager = new TaskManager();

            int userId = int.Parse(User.Identity.GetProjectUserId());
            var projectId = manager.GetProjectForTask(taskId).Id;
            DateTime startTime = DateTime.Now.AddHours(1);
            DateTime endTime = DateTime.Now;
            try
            {
                startTime = DateTime.Parse(Request.Form["startTime"]);
                endTime = DateTime.Parse(Request.Form["endTime"]);
            }
            catch (Exception ex)
            {
                TempData["errorMessage"] = "Wrong date/time format!";
            }

            if (startTime < endTime && startTime.AddMinutes(-5) < DateTime.Now)
            {
                WorktimeData data = new WorktimeData()
                {
                    ProjectUserId = userId,
                    TaskId = taskId,
                    StartTime = startTime,
                    EndTime = endTime
                };

                if (!manager.AddWorkTime(data))
                {
                    TempData["errorMessage"] = "Overlapping work time!";
                }
            }
            else
            {
                TempData["errorMessage"] = "Invalid start or end time!";
            }

            TempData["DetailsPage"] = "1";
            TempData["overlayId"] = "TaskDetails";
            TempData["TaskDetailsId"] = "" + taskId;
            return Redirect("/Projects/Details/" + projectId);
        }
Esempio n. 2
0
        public bool AddWorkTime(WorktimeData data)
        {
            using (var context = new ProjectManagerDBEntities())
            {
                var relatedWorkTimes = context.Worktime.Where(w => w.TaskId == data.TaskId &&
                    w.ProjectUserId == data.ProjectUserId);
                var overLappingWorkTimes = relatedWorkTimes.Where(w =>
                    (data.StartTime > w.StartTime && data.StartTime < w.EndTime) ||
                    (data.EndTime > w.StartTime && data.EndTime < w.EndTime));

                if (overLappingWorkTimes.Count() == 0)
                {

                    context.Worktime.Add(new Worktime()
                    {
                        ProjectUserId = data.ProjectUserId,
                        TaskId = data.TaskId,
                        StartTime = data.StartTime,
                        EndTime = data.EndTime
                    });

                    context.SaveChanges();
                    return true;
                }

                return false;
            }
        }