public ActionResult Create([Bind(Include = "Id,IsOpen,Pet_Id,User_Id")] AdoptionRequest adoptionRequest) { User sessionUser = (User)System.Web.HttpContext.Current.Session["user"]; adoptionRequest.Pet = db.Pets.Find(adoptionRequest.Pet_Id); adoptionRequest.Pet_Id = db.Pets.Find(adoptionRequest.Pet_Id).Id; adoptionRequest.Pet.Organization_Id = adoptionRequest.Pet.Organization.Id; if (adoptionRequest.Pet.IsAdopted) { return(RedirectToAction("Index", "Error", new { message = "The pet is alredy adopted" })); } else { if (adoptionRequest.User_Id == null) { adoptionRequest.User = db.Users.Find(sessionUser.Id); adoptionRequest.User_Id = db.Users.Find(sessionUser.Id).Id; } else { adoptionRequest.User = db.Users.Find(adoptionRequest.User_Id); adoptionRequest.User_Id = db.Users.Find(adoptionRequest.User_Id).Id; } var ar = from b in db.AdoptionRequests.Where(x => x.Pet_Id == adoptionRequest.Pet.Id) select b; foreach (AdoptionRequest item in ar) { if (item.User_Id == adoptionRequest.User.Id) { return(RedirectToAction("Index", "Error", new { message = "The adoption request for " + adoptionRequest.Pet.Name + " alredy exist for " + adoptionRequest.User.Username })); } } if (ModelState.IsValid) { adoptionRequest.IsOpen = true; db.AdoptionRequests.Add(adoptionRequest); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(adoptionRequest)); } }
public List <UserStoryViewModel> InsertUserStory(UserStory usInput) { _context.UserStories.Add(usInput); _context.SaveChanges(); return(GetUserStoriesByPaging(1, pageSize)); }
public List <ProjectTaskViewModel> InsertProjectTask(ProjectTask ptInput) { _context.ProjectTasks.Add(ptInput); _context.SaveChanges(); return(GetProjectTasksByPaging(1, pageSize)); }
public List <Project> InsertProject(Project p) { _context.Projects.Add(p); _context.SaveChanges(); return(GetProjectsByPaging(1, pageSize)); }
/// <summary> /// Persist changes to the data source. /// </summary> public void Save() { s_logger.Info("Saving changes to the database"); _locationContext.SaveChanges(); }
public List <CommentViewModel> InsertManagerComment(ManagerComment mc) { _context.ManagerComments.Add(mc); _context.SaveChanges(); return(GetTaskComments(mc.ProjectTaskID)); }
private void Seed() { using (var context = new ProjectDBContext(options)) { context.Database.EnsureDeleted(); context.Database.EnsureCreated(); context.SavedProject.AddRange( new SavedProject { Id = 1, BPM = "1", ProjectName = "test1", }, new SavedProject { Id = 2, BPM = "2", ProjectName = "test2" } ); context.Track.AddRange( new Track { Id = 1, PatternId = 1, ProjectId = 1, SampleId = 1 }, new Track { Id = 2, SampleId = 2, ProjectId = 2, PatternId = 2 } ); context.Sample.AddRange( new Sample { Id = 1, SampleLink = "SampleLink1", SampleName = "SampleName1" }, new Sample { Id = 2, SampleLink = "SampleLink2", SampleName = "SampleName2" } ); context.Pattern.AddRange( new Pattern { Id = 1, PatternData = "PatternData1", }, new Pattern { Id = 2, PatternData = "PatternData2" } ); context.UserProject.AddRange( new UserProject { Id = 1, UserId = 1, ProjectId = 1, Owner = false }, new UserProject { Id = 2, ProjectId = 2, UserId = 2, Owner = false } ); context.UsersSampleSets.AddRange( new UsersSampleSets { Id = 1, UserId = 1, SampleSetsId = 1 }, new UsersSampleSets { Id = 2, SampleSetsId = 2, UserId = 2 } ); context.SamplePlaylist.AddRange( new SamplePlaylist { Id = 1, SampleId = 1, SampleSetId = 1 }, new SamplePlaylist { Id = 2, SampleSetId = 2, SampleId = 2 } ); context.UsersSample.AddRange( new UsersSample { Id = 1, SampleId = 1, UserId = 1 }, new UsersSample { Id = 2, SampleId = 2, UserId = 2 } ); context.SampleSet.AddRange( new SampleSets { Id = 1, Name = "SampleSet1" }, new SampleSets { Id = 2, Name = "SampleSet2" } ); context.SaveChanges(); } }
public void Add(T Entity) { db.Entry(Entity).State = System.Data.Entity.EntityState.Added; db.SaveChanges(); }
public List <EmployeeViewModel> InsertEmployee(Employee e) { _context.Employees.Add(e); _context.SaveChanges(); return(GetAllEmployees("", 1, pageSize)); }