Exemplo n.º 1
0
        /// <summary>
        /// TODO: Delete this when admin screens done!
        /// </summary>
        public static void TempInit()
        {
            AllProjects t3 = new AllProjects();

            if (t3.Count == 0)
            {
                t3.Add(new Project {
                    Id = Guid.NewGuid(), Description = "Test Project", Active = true
                });
                t3.Save();
            }

            AllTasks t1 = new AllTasks();

            if (t1.Count == 0)
            {
                t1.Add(new Task {
                    Id = Guid.NewGuid(), ProjectId = t3[0].Id, Description = "Test Task 1", Active = true
                });
                t1.Save();
            }

            AllUserTaskAccess t5 = new AllUserTaskAccess();

            if (t5.Count == 0)
            {
                t5.Add(new UserTaskAccess {
                    ProjectId = t3[0].Id, TaskId = t1[0].Id, UserId = new AllUsers()[0].UserId
                });
                t5.Save();
            }
        }
Exemplo n.º 2
0
        public static List <ValidationMessage> SaveProject(
            ValidatableParameter <string> projectId,
            ValidatableParameter <string> details,
            ValidatableParameter <bool> active
            )
        {
            List <ValidationMessage> errors = new List <ValidationMessage>();

            Guid projId = Guid.Empty;

            try
            {
                projId = new Guid(projectId.Value);
            }
            catch (FormatException)
            {
                errors.Add(new ValidationMessage {
                    MessageText = "Project Id must be in the format dddddddd-dddd-dddd-dddd-dddddddddddd", Source = projectId.Source
                });
            }

            if (string.IsNullOrEmpty(details.Value) || details.Value.Trim().Length == 0)
            {
                errors.Add(new ValidationMessage {
                    MessageText = "Project Name must be supplied", Source = details.Source
                });
            }
            else
            {
                //check for existing name with different id (name already in use)
                Project existItem = AllProjects.GetForName(details.Value);
                if (existItem != null && existItem.Id != projId)
                {
                    errors.Add(new ValidationMessage {
                        MessageText = string.Format("Project Name is already in use by project with Id {0}", existItem.Id.ToString()), Source = details.Source
                    });
                }
            }

            //perform update if no errors
            if (errors.Count == 0)
            {
                AllProjects items   = new AllProjects();
                Project     newItem = new Project {
                    Id = projId, Description = details.Value, Active = active.Value
                };
                if (projId == Guid.Empty)
                {
                    newItem.Id = Guid.NewGuid(); //set id
                    items.Add(newItem);
                }
                else
                {
                    Project existItem = items.Where(i => i.Id == projId).Single();
                    items.Remove(existItem);
                    items.Add(newItem);
                }

                items.Save();
            }

            return(errors);
        }