Esempio n. 1
0
        public ActionResult Create(TaskFormModel model)
        {
            var task = TaskService.TaskNew();

            this.MapToObject(model, task);

            task = TaskService.TaskSave(task);

            if (task.IsValid)
            {
                if (model.HourId != 0)
                {
                    var hour = HourService.HourFetch(model.HourId);

                    hour.TaskId = task.TaskId;

                    HourService.HourSave(hour);
                }

                return new JsonResult { Data = this.Url.Action("Edit", new { id = task.TaskId, message = Resources.SaveSuccessfulMessage }) };
            }

            this.MapToModel(task, model, false);

            return this.View(model);
        }
Esempio n. 2
0
        public ActionResult Create(int? hourId)
        {
            var model = new TaskFormModel();

            try
            {
                Task task;

                if (hourId != null)
                {
                    task = TaskService.TaskNew(HourService.HourFetch((int)hourId));
                }
                else
                {
                    task = TaskService.TaskNew();
                }

                this.MapToModel(task, model, true);
            }
            catch (Exception ex)
            {
                this.ModelState.AddModelError(string.Empty, ex.Message);
            }

            return this.View(model);
        }
Esempio n. 3
0
        public ActionResult Delete(int id)
        {
            var model = new TaskFormModel();

            try
            {
                var task = TaskService.TaskFetch(id);

                this.MapToModel(task, model, true);
            }
            catch (Exception ex)
            {
                this.ModelState.AddModelError(string.Empty, ex.Message);
            }

            return this.View(model);
        }
Esempio n. 4
0
        private void MapToObject(TaskFormModel model, Task task)
        {
            Csla.Data.DataMapper.Map(
                model, task, true, "EstimatedCompletedDate", "CompletedDate", "AssignedDate", "StartDate", "Labels");

            if (model.Labels == null)
            {
                return;
            }

            switch (SettingHelper.LabelMode)
            {
                case ConfigurationMode.Simple:
                    task.Labels = model.Labels;
                    break;
                case ConfigurationMode.Advanced:
                    var labels = model.Labels.Split(' ');

                    foreach (var label in labels.Where(label => !task.TaskLabels.Contains(label)))
                    {
                        task.TaskLabels.Add(label);
                    }

                    var taskLabelsToRemove = (from taskLabel
                                                  in task.TaskLabels
                                              where !labels.Contains(taskLabel.Name)
                                              select taskLabel.Name)
                        .ToList();

                    foreach (var taskLabel in taskLabelsToRemove)
                    {
                        task.TaskLabels.Remove(taskLabel);
                    }

                    break;
                default:
                    break;
            }
        }
Esempio n. 5
0
        private void MapToModel(Task task, TaskFormModel model, bool ignoreBrokenRules)
        {
            Csla.Data.DataMapper.Map(task, model, true, "Labels");

            model.Tab = "Task";
            model.Statuses = DataHelper.GetStatusList();
            model.Categories = DataHelper.GetCategoryList();
            model.Projects = DataHelper.GetProjectList();
            model.Sprints = DataHelper.GetSprintList(task.ProjectId);
            model.Users = DataHelper.GetUserList();

            if (!task.IsNew)
            {
                model.Hours = HourService.HourFetchInfoList(task)
                        .OrderBy(row => row.Date)
                        .AsQueryable();

                model.Invoices = InvoiceService.InvoiceFetchInfoList(task)
                         .OrderByDescending(row => row.Number)
                         .AsQueryable();

                model.NoteListModel =
                    new NoteListModel
                    {
                        Source = task,
                        Notes = NoteService.NoteFetchInfoList(task).AsQueryable()
                    };

                model.LabelListModel =
                    new LabelListModel
                    {
                        Action = "Task",
                        Labels = task.TaskLabels.Select(row => row.Name)
                    };

                model.AttachmentListModel =
                    new AttachmentListModel
                    {
                        Source = task,
                        Attachments = AttachmentService.AttachmentFetchInfoList(task).AsQueryable()
                    };
            }

            switch (SettingHelper.LabelMode)
            {
                case ConfigurationMode.Simple:
                    model.Labels = task.Labels;
                    break;
                case ConfigurationMode.Advanced:
                    model.Labels = task.TaskLabels.ToString();
                    break;
                default:
                    break;
            }

            model.IsNew = task.IsNew;
            model.IsValid = task.IsValid;

            if (ignoreBrokenRules)
            {
                return;
            }

            foreach (var brokenRule in task.BrokenRulesCollection)
            {
                this.ModelState.AddModelError(string.Empty, brokenRule.Description);
            }
        }
Esempio n. 6
0
        public ActionResult Edit(int id, TaskFormModel model)
        {
            var task = TaskService.TaskFetch(id);

            this.MapToObject(model, task);

            task = TaskService.TaskSave(task);

            if (task.IsValid)
            {
                model.Message = Resources.SaveSuccessfulMessage;
            }

            this.MapToModel(task, model, true);

            return this.View(model);
        }