Example #1
0
        public Project CreateProject(Project project)
        {
            ProjectData newProject = Mapper.MapProject(project);

            newProject.ProjectId = Guid.NewGuid().ToString();

            using (var context = new ZenchiDBContext())
            {
                context.ProjectData.Add(newProject);
                context.SaveChanges();

                return(Mapper.MapProject(newProject));
            }
        }
Example #2
0
        public void DeleteProject(string projectId)
        {
            using (var context = new ZenchiDBContext())
            {
                ProjectData dbItem = context.ProjectData
                                     .Where(p => p.ProjectId == projectId)
                                     .FirstOrDefault();

                if (dbItem == null)
                {
                    throw new KeyNotFoundException();
                }

                context.ProjectData.Remove(dbItem);
                context.SaveChanges();
            }
        }
Example #3
0
        public Project UpdateProject(Project project)
        {
            using (var context = new ZenchiDBContext())
            {
                ProjectData dbItem = context.ProjectData
                                     .Where(p => p.ProjectId == project.ProjectId)
                                     .FirstOrDefault();

                if (dbItem == null)
                {
                    throw new KeyNotFoundException();
                }

                var updateItem = Mapper.MapProject(project);
                updateItem.Id = dbItem.Id;

                context.Set <ProjectData>().AddOrUpdate(updateItem);
                context.SaveChanges();

                return(Mapper.MapProject(updateItem));
            }
        }