コード例 #1
0
        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));
            }
        }
コード例 #2
0
 public List <UserStoryViewModel> InsertUserStory(UserStory usInput)
 {
     _context.UserStories.Add(usInput);
     _context.SaveChanges();
     return(GetUserStoriesByPaging(1, pageSize));
 }
コード例 #3
0
 public List <ProjectTaskViewModel> InsertProjectTask(ProjectTask ptInput)
 {
     _context.ProjectTasks.Add(ptInput);
     _context.SaveChanges();
     return(GetProjectTasksByPaging(1, pageSize));
 }
コード例 #4
0
 public List <Project> InsertProject(Project p)
 {
     _context.Projects.Add(p);
     _context.SaveChanges();
     return(GetProjectsByPaging(1, pageSize));
 }
コード例 #5
0
 /// <summary>
 /// Persist changes to the data source.
 /// </summary>
 public void Save()
 {
     s_logger.Info("Saving changes to the database");
     _locationContext.SaveChanges();
 }
コード例 #6
0
 public List <CommentViewModel> InsertManagerComment(ManagerComment mc)
 {
     _context.ManagerComments.Add(mc);
     _context.SaveChanges();
     return(GetTaskComments(mc.ProjectTaskID));
 }
コード例 #7
0
        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();
            }
        }
コード例 #8
0
 public void Add(T Entity)
 {
     db.Entry(Entity).State = System.Data.Entity.EntityState.Added;
     db.SaveChanges();
 }
コード例 #9
0
 public List <EmployeeViewModel> InsertEmployee(Employee e)
 {
     _context.Employees.Add(e);
     _context.SaveChanges();
     return(GetAllEmployees("", 1, pageSize));
 }