Пример #1
0
        public ActionResult Edit(TaskSummary item, string fromUrl)
        {
            TaskManager manager = new TaskManager();

            try
            {
                item.IsNew = false;
                manager.Save(item);

                // Save the files once it's saved (as we can't add an AttachmentsCollection as it has no constructors)
                if (Request.Files.Count > 0)
                {
                    try
                    {
                        // Save to the App_Data folder.
                        List<Attachment> attachments = new List<Attachment>();
                        string filename1 = SaveFile("uploadFile1", item.Id);
                        string filename2 = SaveFile("uploadFile2", item.Id);
                        string filename3 = SaveFile("uploadFile3", item.Id);

                        if (!string.IsNullOrEmpty(filename1))
                        {
                            attachments.Add(new Attachment(filename1, Request.Form["uploadFile1Comments"]));
                        }
                        if (!string.IsNullOrEmpty(filename2))
                        {
                            attachments.Add(new Attachment(filename2, Request.Form["uploadFile2Comments"]));
                        }
                        if (!string.IsNullOrEmpty(filename3))
                        {
                            attachments.Add(new Attachment(filename3, Request.Form["uploadFile3Comments"]));
                        }

                        manager.SaveAttachments(item.Id, attachments);
                    }
                    catch (IOException e)
                    {
                        TempData["Error"] = e.Message;
                        return RedirectToAction("Edit", new { id = item.Id });
                    }
                }

                if (string.IsNullOrEmpty(fromUrl))
                    return RedirectToAction("View", new { id = item.Id });
                else
                    return Redirect(fromUrl);
            }
            catch (SaveException e)
            {
                TempData["Error"] = e.Message;

                // Get the original back, to populate the valid reasons.
                QueryManager queryManager = new QueryManager();
                TaskSummary summary = queryManager.ItemById<TaskSummary>(item.Id);
                summary.IsNew = false;

                // Repopulate from the POST'd data
                summary.Title = item.Title;
                summary.State = item.State;
                summary.Reason = item.Reason;
                summary.Priority = item.Priority;
                summary.Description = item.Description;
                summary.AssignedTo = item.AssignedTo;
                summary.AreaId = item.AreaId;
                summary.AreaPath = item.AreaPath;
                summary.IterationId = item.IterationId;
                summary.IterationPath = item.IterationPath;

                MSAgileEditData<TaskSummary> data = new MSAgileEditData<TaskSummary>();
                data.WorkItem = summary;
                data.PageTitle = "Task " + item.Id;
                data.FromUrl = fromUrl;
                data.States = summary.ValidStates;
                data.Reasons = summary.ValidReasons;
                data.Priorities = summary.ValidPriorities;
                data.Severities = summary.ValidSeverities;

                return View(data);
            }
        }
Пример #2
0
        public ActionResult New(string id)
        {
            TaskManager manager = new TaskManager();
            TaskSummary summary = (TaskSummary)manager.NewItem();

            if (!string.IsNullOrWhiteSpace(id))
                summary.Title = id;

            MSAgileEditData<TaskSummary> data = new MSAgileEditData<TaskSummary>();
            data.PageTitle = "New task";
            data.States = summary.ValidStates;
            data.Reasons = summary.ValidReasons;
            data.Priorities = summary.ValidPriorities;
            data.Severities = summary.ValidSeverities;
            data.WorkItem = summary;

            return View("Edit", data);
        }