/// <summary>
        /// Saves a project in the database
        /// </summary>
        /// <param name="project">The project detail to save</param>
        /// <returns>Returns true if the insert was successful. False if it failed</returns>
        public static bool UpdateProject(ProjectDetails project)
        {
            try
            {
                using (UniblueLabsEntities entities = new UniblueLabsEntities())
                {
                    Projects projectToUpdate = entities.Projects.First(x => x.id == project.ProjectId);
                    if (projectToUpdate != null)
                    {
                        projectToUpdate.Name        = project.Name;
                        projectToUpdate.Description = project.Description;
                        projectToUpdate.Link        = project.Link;
                        projectToUpdate.Developers  = entities.Developers.Where(x => x.id == project.DeveloperId).FirstOrDefault();
                    }
                    else
                    {
                        return(false);
                    }

                    entities.SaveChanges();
                }
            }
            catch
            {
                return(false);
            }
            return(true);
        }
예제 #2
0
        /// <summary>
        /// Saves a project in the database
        /// </summary>
        /// <param name="project">The project detail to save</param>
        /// <returns>Returns true if the insert was successful. False if it failed</returns>
        public static bool UpdateProject(ProjectDetails project)
        {
            try
            {
                using (UniblueLabsEntities entities = new UniblueLabsEntities())
                {
                    Projects projectToUpdate = entities.Projects.First(x => x.id == project.ProjectId);
                    if (projectToUpdate != null)
                    {
                        projectToUpdate.Name = project.Name;
                        projectToUpdate.Description = project.Description;
                        projectToUpdate.Link = project.Link;
                        projectToUpdate.Developers = entities.Developers.Where(x => x.id == project.DeveloperId).FirstOrDefault();
                    }
                    else
                        return false;

                    entities.SaveChanges();
                }
            }
            catch
            {
                return false;
            }
            return true;
        }
        private void Save(object x)
        {
            if (IsEditMode)
            {
                if (ProjectsDataService.UpdateProject(Project))
                {
                    Mediator.NotifyColleagues(ViewModelMessages.NotificationMessage, "Project details updated!");
                }
                else
                {
                    Mediator.NotifyColleagues(ViewModelMessages.ShowError, "Error saving project in database");
                }
            }
            else
            {
                if (ProjectsDataService.AddNewProject(Project))
                {
                    //Notify Mediator that the project was added
                    Mediator.NotifyColleagues(ViewModelMessages.NewProjectAdded, Project);
                    //also send a notification to user
                    Mediator.NotifyColleagues(ViewModelMessages.NotificationMessage, "New project added!");

                    //clear the fields in the View
                    Project = new WPFDisciples.Backend.ProjectDetails();
                }
                else
                {
                    //Notify Mediator there was an error
                    Mediator.NotifyColleagues(ViewModelMessages.ShowError, "Error saving project in database");
                }
            }
        }
 public static bool DeleteProject(ProjectDetails projectDetails)
 {
     try
     {
         using (UniblueLabsEntities entities = new UniblueLabsEntities())
         {
             var proj = entities.Projects.FirstOrDefault(x => x.id == projectDetails.ProjectId);
             entities.DeleteObject(proj);
             entities.SaveChanges();
         }
     }
     catch
     {
         return(false);
     }
     return(true);
 }
        public ProjectDetailsViewModel()
        {
            Project = new WPFDisciples.Backend.ProjectDetails();

            //initialize the ShowDevelopers Command
            ShowDevelopers = new SimpleCommand
            {
                //Notify listeners to show the developers View
                ExecuteDelegate = x => Mediator.NotifyColleagues(ViewModelMessages.ShowDevelopers, null)
            };

            ShowRichText = new SimpleCommand
            {
                //Notify listeners to show the rich text View
                ExecuteDelegate = x => Mediator.NotifyColleagues(ViewModelMessages.ShowRichText, x)
            };

            SaveProject = new SimpleCommand
            {
                ExecuteDelegate = Save,
                //Can execute only if there are no errors
                CanExecuteDelegate = x => String.IsNullOrEmpty(Project.Error)
            };

            Mediator.Register(
                x =>
            {
                WPFDisciples.Backend.Developers dev = x as WPFDisciples.Backend.Developers;
                if (dev != null)
                {
                    Project.Developer    = dev.Name;
                    Project.DeveloperId  = dev.id;
                    Project.DeveloperPic = dev.Avatar;
                }
            },
                ViewModelMessages.SelectDeveloper);

            //Receive a notification with the new Text that was entered in the RichText view for the Description
            Mediator.Register(x => Project.Description = x.ToString(), ViewModelMessages.HideRichText);
        }
예제 #6
0
        public ProjectDetailsViewModel()
        {
            Project = new WPFDisciples.Backend.ProjectDetails();

            //initialize the ShowDevelopers Command
            ShowDevelopers = new SimpleCommand
            {
                //Notify listeners to show the developers View
                ExecuteDelegate = x => Mediator.NotifyColleagues(ViewModelMessages.ShowDevelopers, null)
            };

            ShowRichText = new SimpleCommand
            {
                //Notify listeners to show the rich text View
                ExecuteDelegate = x => Mediator.NotifyColleagues(ViewModelMessages.ShowRichText, x)
            };

            SaveProject = new SimpleCommand
            {
                ExecuteDelegate = Save,
                //Can execute only if there are no errors
                CanExecuteDelegate = x => String.IsNullOrEmpty(Project.Error)
            };

            Mediator.Register(
                x =>
                {
                    WPFDisciples.Backend.Developers dev = x as WPFDisciples.Backend.Developers;
                    if (dev != null)
                    {
                        Project.Developer = dev.Name;
                        Project.DeveloperId = dev.id;
                        Project.DeveloperPic = dev.Avatar;
                    }
                },
                ViewModelMessages.SelectDeveloper);

            //Receive a notification with the new Text that was entered in the RichText view for the Description
            Mediator.Register(x => Project.Description = x.ToString(), ViewModelMessages.HideRichText);
        }
예제 #7
0
 /// <summary>
 /// Saves a project in the database
 /// </summary>
 /// <param name="project">The project detail to save</param>
 /// <returns>Returns true if the insert was successful. False if it failed</returns>
 public static bool AddNewProject(ProjectDetails project)
 {
     try
     {
         using (UniblueLabsEntities entities = new UniblueLabsEntities())
         {
             Projects newProject = new Projects
             {
                 Name = project.Name,
                 Description = project.Description,
                 Link = project.Link,
                 Developers = entities.Developers.Where(x => x.id == project.DeveloperId).FirstOrDefault(),
             };
             entities.AddToProjects(newProject);
             entities.SaveChanges();
             project.ProjectId = newProject.id;
         }
     }
     catch
     {
         return false;
     }
     return true;
 }
 /// <summary>
 /// Saves a project in the database
 /// </summary>
 /// <param name="project">The project detail to save</param>
 /// <returns>Returns true if the insert was successful. False if it failed</returns>
 public static bool AddNewProject(ProjectDetails project)
 {
     try
     {
         using (UniblueLabsEntities entities = new UniblueLabsEntities())
         {
             Projects newProject = new Projects
             {
                 Name        = project.Name,
                 Description = project.Description,
                 Link        = project.Link,
                 Developers  = entities.Developers.Where(x => x.id == project.DeveloperId).FirstOrDefault(),
             };
             entities.AddToProjects(newProject);
             entities.SaveChanges();
             project.ProjectId = newProject.id;
         }
     }
     catch
     {
         return(false);
     }
     return(true);
 }
예제 #9
0
        public static bool DeleteProject(ProjectDetails projectDetails)
        {
            try
            {
                using (UniblueLabsEntities entities = new UniblueLabsEntities())
                {
                    var proj = entities.Projects.FirstOrDefault(x => x.id == projectDetails.ProjectId);
                    entities.DeleteObject(proj);
                    entities.SaveChanges();
                }
            }
            catch
            {
                return false;
            }
            return true;

        }
예제 #10
0
        private void Save(object x)
        {
            if (IsEditMode)
            {
                if (ProjectsDataService.UpdateProject(Project))
                    Mediator.NotifyColleagues(ViewModelMessages.NotificationMessage, "Project details updated!");
                else
                    Mediator.NotifyColleagues(ViewModelMessages.ShowError, "Error saving project in database");
            }
            else
            {
                if (ProjectsDataService.AddNewProject(Project))
                {
                    //Notify Mediator that the project was added
                    Mediator.NotifyColleagues(ViewModelMessages.NewProjectAdded, Project);
                    //also send a notification to user
                    Mediator.NotifyColleagues(ViewModelMessages.NotificationMessage, "New project added!");

                    //clear the fields in the View
                    Project = new WPFDisciples.Backend.ProjectDetails();
                }
                else
                    //Notify Mediator there was an error
                    Mediator.NotifyColleagues(ViewModelMessages.ShowError, "Error saving project in database");
            }
        }