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); }
public ActionResult Edit(int Id) { var db = new MVCContext(); var std = db.Students.Where(s => s.StudentId == Id).FirstOrDefault(); return(View(std)); }
public int GetID(string email) { using (var ctx = new MVCContext()) { var user = ctx.Users.Where(u => u.email == email).FirstOrDefault(); return(user.ID); } }
public IEnumerable <PhotoDataModel> All() { using (var ctx = new MVCContext()) { var photos = ctx.Photos .Include(p => p.Comments) .Include(p => p.Album) .Include(p => p.User); return(photos.ToList()); } }
public IEnumerable <CommentsDataModel> All() { using (var ctx = new MVCContext()) { var comments = ctx.Comments .Include(c => c.User) .Include(c => c.Photo); return(comments.ToList()); } }
public PhotoDataModel ByID(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(); return(photo); } }
public CommentsDataModel ByID(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(); return(comment); } }
public IEnumerable <AlbumDataModel> All() { using (var ctx = new MVCContext()) { var albums = ctx.Albums .Include(g => g.photos) .Include(g => g.User) ; return(albums.ToList()); } }
public AlbumDataModel ByID(int ID) { using (var ctx = new MVCContext()) { var albums = ctx.Albums.Where(g => g.ID == ID) .Include(g => g.photos) .Include(g => g.User) . FirstOrDefault(); return(albums); } }
public IEnumerable <UserDataModel> All() { using (var ctx = new MVCContext()) { var users = ctx.Users .Include(u => u.Albums) .Include(u => u.Comments) .Include(u => u.Photos); return(users.ToList()); } }
public UserDataModel ByID(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(); return(user); } }
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)); }
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()); }
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); }
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); }
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); }
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(); } }
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); }
//IList<Student> studentList = new List <Student> { // new Student() { StudentId = 1, StudentName = "John", Age = 18, isNewlyEnrolled = true, Password = "******", Gender = Gender.Male} , // new Student() { StudentId = 2, StudentName = "Steve", Age = 21, isNewlyEnrolled = false, Password = "******", Gender = Gender.Male} , // new Student() { StudentId = 3, StudentName = "Bill", Age = 25, isNewlyEnrolled = false, Password = "******", Gender = Gender.Male} , // new Student() { StudentId = 4, StudentName = "Anna" , Age = 20, isNewlyEnrolled = true, Password = "******", Gender = Gender.Female} , // new Student() { StudentId = 5, StudentName = "Ron" , Age = 31, isNewlyEnrolled = false, Password = "******", Gender = Gender.Male} , // new Student() { StudentId = 4, StudentName = "Chris" , Age = 17, isNewlyEnrolled = true, Password = "******", Gender = Gender.Male} , // new Student() { StudentId = 4, StudentName = "Elena" , Age = 19, isNewlyEnrolled = true, Password = "******", Gender = Gender.Female} //}; // GET: Student public ActionResult Index() { //return View(studentList); var db = new MVCContext(); var allStudents = db.Students.ToList(); //using (var db = new MVCContext()) //{ //var customer = new Student() //{ // StudentName = "Johne" //}; //db.Students.Add(customer); //db.SaveChanges(); //} return(View(allStudents)); }
public int GetNewIndex() { using (var ctx = new MVCContext()) { var comments = ctx.Comments .Include(c => c.User) .Include(c => c.Photo); var res = comments.OrderBy(x => x.ID).LastOrDefault(); if (res == null) { return(1); } else { return(res.ID + 1); } } }
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); }
public int GetNewIndex() { using (var ctx = new MVCContext()) { var photos = ctx.Photos .Include(p => p.Comments) .Include(p => p.Album) .Include(p => p.User); var res = photos.OrderByDescending(i => i.ID).FirstOrDefault(); if (res == null) { return(1); } else { return(res.ID + 1); } } }
public int GetNewIndex() { using (var ctx = new MVCContext()) { var users = ctx.Users .Include(u => u.Albums) .Include(u => u.Comments) .Include(u => u.Photos); var res = users.OrderBy(x => x.ID).LastOrDefault(); if (res == null) { return(1); } else { return(res.ID + 1); } } }
public int GetNewIndex() { using (var ctx = new MVCContext()) { var albums = ctx.Albums .Include(g => g.photos) .Include(g => g.User) ; var res = albums.OrderBy(x => x.ID).LastOrDefault(); if (res == null) { return(1); } else { return(res.ID + 1); } } }
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); } } }
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); }
public HomeController(ILogger <HomeController> logger, IWebHostEnvironment webHostEnvironment, MVCContext context) { _logger = logger; _webHostEnvironment = webHostEnvironment; _context = context; }
public ToDoesController(MVCContext context) { _context = context; }
public OtsAccessesController(MVCContext context) { _context = context; }
public LrvRolegroupsController(MVCContext context) { _context = context; }