public void Insert(T entity)
 {
     if (entity == null)
     {
         throw new ArgumentNullException("entity");
     }
     entities.Add(entity);
     context.SaveChanges();
 }
Example #2
0
        public ActionResult Create([Bind(Include = "ID,WorkRole,CompanyName,StartDate,EndDate,Description")] Experience experience)
        {
            if (ModelState.IsValid)
            {
                db.Experiences.Add(experience);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(experience));
        }
Example #3
0
        public ActionResult Create([Bind(Include = "ID,Name,Address,City,ZipCode,PhoneNumber,Email")] Person person)
        {
            if (ModelState.IsValid)
            {
                db.People.Add(person);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(person));
        }
        public ActionResult Create([Bind(Include = "Id,FirstName,LastName,Age")] Customer customer)
        {
            if (ModelState.IsValid)
            {
                db.Customers.Add(customer);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(customer));
        }
Example #5
0
        public ActionResult Create([Bind(Include = "RoomId,Name")] Room room)
        {
            if (ModelState.IsValid)
            {
                db.Rooms.Add(room);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(room));
        }
Example #6
0
        public ActionResult Create([Bind(Include = "ID,Description")] Skills skills)
        {
            if (ModelState.IsValid)
            {
                db.Skills.Add(skills);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(skills));
        }
Example #7
0
        public ActionResult Create([Bind(Include = "Id,Nome,Telefone,CPF")] Cliente cliente)
        {
            if (ModelState.IsValid)
            {
                db.Clientes.Add(cliente);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(cliente));
        }
Example #8
0
        public ActionResult Create([Bind(Include = "ID,Name,School,StartDate,EndDate")] Education education)
        {
            if (ModelState.IsValid)
            {
                db.Educations.Add(education);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(education));
        }
Example #9
0
        public bool AddOrUpdate(PhotoDataModel photo)
        {
            try
            {
                using (var ctx = new MVCContext())
                {
                    var photoToUpdate = ctx.Photos.Where(p => p.ID == photo.ID)
                                        .Include(p => p.User)
                                        .Include(p => p.Comments)
                                        .Include(p => p.Album)
                                        .FirstOrDefault();


                    if (photoToUpdate != null)
                    {
                        photoToUpdate.Name        = photo.Name;
                        photoToUpdate.AlbumID     = photo.AlbumID;
                        photoToUpdate.Path        = photo.Path;
                        photoToUpdate.publik      = photo.publik;
                        photoToUpdate.Description = photo.Description;
                        photoToUpdate.Datecreated = photo.Dateupdated;
                        ctx.SaveChanges();
                        return(true);
                    }
                    else
                    {
                        var newPhoto = new PhotoDataModel();
                        newPhoto.User        = photo.User;
                        newPhoto.Album       = photo.Album;
                        newPhoto.Name        = photo.Name;
                        newPhoto.AlbumID     = photo.AlbumID;
                        newPhoto.Path        = photo.Path;
                        newPhoto.publik      = photo.publik;
                        newPhoto.Description = photo.Description;
                        newPhoto.Datecreated = photo.Datecreated;
                        newPhoto.Dateupdated = photo.Dateupdated;
                        newPhoto.UserID      = photo.UserID;
                        ctx.Photos.Add(newPhoto);
                        ctx.SaveChanges();
                        return(true);
                    }
                }
            }
            catch (Exception e)
            {
                //Handle exceptions
            }
            return(false);
        }
Example #10
0
        public bool AddOrUpdate(CommentsDataModel comment)
        {
            try
            {
                using (var ctx = new MVCContext())
                {
                    var commentToUpdate = ctx.Comments.Where(c => c.ID == comment.ID)
                                          .Include(c => c.User)
                                          .Include(c => c.Photo)

                                          .FirstOrDefault();
                    if (commentToUpdate != null)     //EDIT
                    {
                        commentToUpdate.User  = comment.User;
                        commentToUpdate.Photo = comment.Photo;


                        commentToUpdate.UserID      = comment.UserID;
                        commentToUpdate.PhotoID     = comment.PhotoID;
                        commentToUpdate.Comment     = comment.Comment;
                        commentToUpdate.Title       = comment.Title;
                        commentToUpdate.Dateupdated = comment.Dateupdated;
                        ctx.SaveChanges();
                        return(true);
                    }
                    else
                    {
                        var newComment = new CommentsDataModel();

                        newComment.User        = comment.User;
                        newComment.Photo       = comment.Photo;
                        newComment.Comment     = comment.Comment;
                        newComment.Title       = comment.Title;
                        newComment.Datecreated = comment.Datecreated;
                        newComment.Dateupdated = comment.Dateupdated;
                        newComment.UserID      = comment.UserID;
                        newComment.PhotoID     = comment.PhotoID;
                        ctx.Comments.Add(newComment);
                        ctx.SaveChanges();
                        return(true);
                    }
                }
            }
            catch (Exception e)
            {
                //Handle exceptions
            }
            return(false);
        }
Example #11
0
        public bool Delete(int ID)
        {
            using (var ctx = new MVCContext())
            {
                var album = ctx.Albums.Where(g => g.ID == ID)
                            .Include(g => g.photos)
                            .Include(g => g.User)

                            .
                            FirstOrDefault();

                if (album != null)
                {
                    foreach (var phot in album.photos)
                    {
                        ctx.Comments.RemoveRange(phot.Comments);
                    }

                    ctx.Photos.RemoveRange(album.photos);



                    ctx.Albums.Remove(album);
                    ctx.SaveChanges();
                    return(true);
                }
            }
            return(false);
        }
Example #12
0
        public bool AddOrUpdate(UserDataModel user)
        {
            try
            {
                using (var ctx = new MVCContext())
                {
                    var userToUpdate = ctx.Users.Where(u => u.ID == user.ID)
                                       .Include(u => u.Albums)
                                       .Include(u => u.Comments)
                                       .Include(u => u.Photos)
                                       .FirstOrDefault();

                    if (userToUpdate != null)
                    {
                        userToUpdate.FirstName = user.FirstName;
                        userToUpdate.LastName  = user.LastName;

                        userToUpdate.email = user.email;

                        userToUpdate.Idguid = user.Idguid;


                        ctx.SaveChanges();
                        return(true);
                    }
                    else
                    {
                        var newUser = new UserDataModel();
                        newUser.FirstName = user.FirstName;
                        newUser.LastName  = user.LastName;

                        newUser.email  = user.email;
                        newUser.Idguid = user.Idguid;

                        ctx.Users.Add(newUser);
                        ctx.SaveChanges();
                        return(true);
                    }
                }
            }
            catch (Exception e)
            {
                //Handle exceptions
            }
            return(false);
        }
Example #13
0
        public bool AddOrUpdate(AlbumDataModel album)
        {
            try
            {
                using (var ctx = new MVCContext())
                {
                    var albumToUpdate = ctx.Albums.Where(g => g.ID == album.ID)
                                        .Include(g => g.photos)
                                        .Include(g => g.User)



                                        .FirstOrDefault();
                    if (albumToUpdate != null)
                    {
                        albumToUpdate.Name        = album.Name;
                        albumToUpdate.Description = album.Description;
                        ctx.SaveChanges();
                        return(true);
                    }
                    else
                    {
                        var newAlbum = new AlbumDataModel();
                        newAlbum.UserID      = album.UserID;
                        newAlbum.User        = album.User;
                        newAlbum.Name        = album.Name;
                        newAlbum.Description = album.Description;
                        newAlbum.DateCreated = DateTime.Now;
                        ctx.Albums.Add(newAlbum);
                        ctx.SaveChanges();
                        return(true);
                    }
                }
            }
            catch (Exception e)
            {
                // handle exceptions
            }

            return(false);
        }
Example #14
0
        public ActionResult Edit(Student std)
        {
            var db = new MVCContext();

            if (ModelState.IsValid)
            {
                db.Entry(std).State = EntityState.Modified;
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(std));
        }
Example #15
0
        public ActionResult Index()
        {
            var context = new MVCContext();

            context.Student.Add(new Student
            {
                Name = "lusi"
            });
            context.SaveChanges();
            var student = context.Student.FirstOrDefault();

            ViewBag.Name = student.Name;
            return(View());
        }
Example #16
0
        public static void Initialize(IServiceProvider serviceProvider)
        {
            using (var context = new MVCContext(serviceProvider.GetRequiredService <DbContextOptions <MVCContext> >()))
            {
                if (context.Movie.Any())
                {
                    return;   // DB has been seeded
                }

                context.Movie.AddRange(
                    new Movie
                {
                    Title       = "When Harry Met Sally",
                    ReleaseDate = DateTime.Parse("1989-2-12"),
                    Genre       = "Romantic Comedy",
                    Price       = 7.99M
                },

                    new Movie
                {
                    Title       = "Ghostbusters ",
                    ReleaseDate = DateTime.Parse("1984-3-13"),
                    Genre       = "Comedy",
                    Price       = 8.99M
                },

                    new Movie
                {
                    Title       = "Ghostbusters 2",
                    ReleaseDate = DateTime.Parse("1986-2-23"),
                    Genre       = "Comedy",
                    Price       = 9.99M
                },

                    new Movie
                {
                    Title       = "Rio Bravo",
                    ReleaseDate = DateTime.Parse("1959-4-15"),
                    Genre       = "Western",
                    Price       = 3.99M
                }
                    );
                context.SaveChanges();
            }
        }
Example #17
0
        public bool Delete(int id)
        {
            using (var ctx = new MVCContext())
            {
                var comment = ctx.Comments.Where(c => c.ID == id)
                              .Include(c => c.User)
                              .Include(c => c.Photo)

                              .FirstOrDefault();
                if (comment != null)
                {
                    ctx.Comments.Remove(comment);
                    ctx.SaveChanges();
                    return(true);
                }
            }
            return(false);
        }
Example #18
0
        public bool Delete(int id)
        {
            using (var ctx = new MVCContext())
            {
                var photo = ctx.Photos.Where(p => p.ID == id)
                            .Include(p => p.User)
                            .Include(p => p.Comments)
                            .Include(p => p.Album)
                            .FirstOrDefault();
                if (photo != null)
                {
                    ctx.Comments.RemoveRange(photo.Comments);


                    ctx.Photos.Remove(photo);
                    ctx.SaveChanges();
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
        }
Example #19
0
        public bool Delete(int id)
        {
            using (var ctx = new MVCContext())
            {
                var user = ctx.Users.Where(u => u.ID == id)
                           .Include(u => u.Albums)
                           .Include(u => u.Comments)
                           .Include(u => u.Photos)
                           .FirstOrDefault();

                if (user != null)
                {
                    //ta bort allt relaterat till user
                    ctx.Photos.RemoveRange(user.Photos);
                    ctx.Comments.RemoveRange(user.Comments);
                    ctx.Albums.RemoveRange(user.Albums);

                    ctx.Users.Remove(user);
                    ctx.SaveChanges();
                    return(true);
                }
            }
            return(false);
        }