Ejemplo n.º 1
0
        public ActionResult Create(StaticFilterCreateDTO filter)
        {
            if (ModelState.IsValid)
            {
                PredefinedStaticFilter newFilter = null;
                if (filter.FilterID != 0)
                {
                    newFilter = this.db.StaticFilters.Find(filter.FilterID);
                    if (newFilter.OwnerID != User.Identity.GetUserId())
                    {
                        return(new HttpStatusCodeResult(HttpStatusCode.Forbidden));
                    }
                }
                else
                {
                    newFilter = new PredefinedStaticFilter();
                }

                newFilter.From      = UnixTime.ParseUnixTimestamp(filter.From);
                newFilter.To        = UnixTime.ParseUnixTimestamp(filter.To);
                newFilter.OwnerID   = User.Identity.GetUserId();
                newFilter.ProjectID = filter.ProjectID;
                newFilter.TaskID    = filter.TaskID;
                newFilter.UserID    = filter.UserID;
                newFilter.Name      = filter.Name;
                db.StaticFilters.Add(newFilter);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }


            return(View(filter));
        }
Ejemplo n.º 2
0
        public ActionResult GetFilteredValues(long?from, long?to, int?projectID, int?taskID, string user)
        {
            DateTime dateFrom;

            if (from != null)
            {
                dateFrom = UnixTime.ParseUnixTimestamp((ulong)from);
            }
            else
            {
                dateFrom = UnixTime.ParseUnixTimestamp(0);
            }

            string           userId    = User.Identity.GetUserId();
            TimeEntriesTable viewModel = new TimeEntriesTable();
            var entries = this.db.TimeEntries
                          .Include(t => t.ParentTask.ParentProject.Roles)
                          .Include(t => t.ParentTask.ParentProject.Rates)
                          .Include(e => e.User)
                          .Where(e => e.ParentTask.OwnerID == userId || e.UserID == userId || e.ParentTask.ParentProject.Roles.Any(r => r.Role == Role.Owner && r.UserID == userId))
                          .Where(t => t.Start > dateFrom);

            if (to != null)
            {
                DateTime dateTo = UnixTime.ParseUnixTimestamp((ulong)to);
                entries = entries.Where(t => t.End < dateTo);
            }
            if (projectID != null)
            {
                entries = entries.Where(e => e.ParentTask.ParentProjectID == projectID);
            }
            if (taskID != null)
            {
                entries = entries.Where(e => e.ParentTaskID == taskID);
            }
            if (!String.IsNullOrWhiteSpace(user))
            {
                entries = entries.Where(e => e.UserID == user);
            }
            viewModel.TimeEntries = entries;
            viewModel.Sum         = TimeSpan.FromSeconds(viewModel.TimeEntries.Sum(e => e.Duration?.TotalSeconds ?? 0));
            viewModel.TotalEarned = viewModel.TimeEntries.Sum(e => e.Charge);
            return(PartialView("~/Views/Partials/TimeEntriesResultsTable.cshtml", viewModel));
        }
Ejemplo n.º 3
0
        public ActionResult Create(TaskCreateDTO form)
        {
            form?.Users.RemoveAll(u => u.Id == null);
            if (ModelState.IsValid)
            {
                ProjectTask task;
                if (form.TaskID != 0)
                {
                    task = this.db.ProjectTasks
                           .Where(x => x.TaskID == form.TaskID)
                           .Include(x => x.Users)
                           .FirstOrDefault();
                    if (task.OwnerID != User.Identity.GetUserId())
                    {
                        return(new HttpStatusCodeResult(HttpStatusCode.Forbidden));
                    }

                    // remove users that are no longer assigned to the task
                    task.Users.RemoveAll(x => !form.Users.Contains(x, new PropertyComparer <ApplicationUser, string>(u => u.Id)));
                    // remove duplicates
                    form.Users.RemoveAll(x => task.Users.Contains(x, new PropertyComparer <ApplicationUser, string>(u => u.Id)));
                }
                else
                {
                    // if not project manager nor owner => task addition refused
                    if ((!this.db.HasProjectRole(form.ParentProjectID, User.Identity.GetUserId(), Role.Manager)))
                    {
                        return(new HttpStatusCodeResult(HttpStatusCode.Forbidden));
                    }
                    task         = new ProjectTask();
                    task.Created = DateTime.UtcNow;
                }
                // task not found
                if (task == null)
                {
                    return(HttpNotFound());
                }
                if (task.Users == null)
                {
                    task.Users = new List <ApplicationUser>();
                }
                task.LastModified    = DateTime.UtcNow;
                task.Deadline        = UnixTime.ParseUnixTimestamp(form.Deadline);
                task.Description     = form.Description;
                task.Name            = form.Name;
                task.OwnerID         = User.Identity.GetUserId();
                task.ParentProjectID = form.ParentProjectID;
                task.Status          = form.Users.Count() > 0 ? TaskStatus.Assigned : TaskStatus.Created;
                form.Users.ForEach(u => this.db.Users.Attach(u));
                form.Users.ForEach(x => task.Users.Add(x));
                List <Attachment> attachments = new List <Attachment>();
                if (task.TaskID == 0)
                {
                    db.ProjectTasks.Add(task);
                }
                db.SaveChanges();

                // save all attachments
                foreach (var val in form.Files)
                {
                    if (val != null)
                    {
                        db.Attachments.Add(new Attachment()
                        {
                            FileName = val.FileName, Size = val.ContentLength, Type = val.ContentType, TaskID = task.TaskID
                        });
                        DirectoryInfo dir = Directory.CreateDirectory(AppDomain.CurrentDomain.BaseDirectory + @"Attachments/" + task.TaskID);
                        val.SaveAs(dir.FullName + @"/" + val.FileName);
                    }
                }

                db.SaveChanges();
                return(this.Redirect("/Projects/Details/" + form.ParentProjectID));
            }
            else
            {
                TaskCreate viewModel = this.getCreateViewModel(form);
                this.prepareCreateViewModel(viewModel);
                return(View(viewModel));
            }
        }