public IActionResult SaveUser(string userId) { List <SavedUser> currentlySaved = _context.SavedUsers.Where(x => x.Employer == User.FindFirst(ClaimTypes.NameIdentifier).Value).ToList(); if (!currentlySaved.Select(x => x.JobSeeker).Contains(userId)) { SavedUser u = new SavedUser(); u.JobSeeker = userId; u.Employer = User.FindFirst(ClaimTypes.NameIdentifier).Value; _context.SavedUsers.Add(u); _context.SaveChanges(); return(RedirectToAction("Index")); } else { TempData["UserError"] = "User already exists in your list"; //List<AspNetUser> profile = _context.AspNetUsers.Where(x => x.Id == userId).ToList(); //ProfileViewModel p = new ProfileViewModel(profile[0]); return(RedirectToAction("UserProfileResult", "Users", new { userId = userId })); } }
public DevPlanViewModel CreateDevPlan(DevPlanDTO devPlan) { _logger.LogInformation("Creating Development Plan..."); _context.DevPlans.Add(Mapper.Map <DevPlan>(devPlan)); _context.SaveChanges(); _logger.LogInformation("Successfully created new development plan."); return(Mapper.Map <DevPlanViewModel>(devPlan)); }
public EmployeeViewModel CreateEmployee(EmployeeDTO employee) { _logger.LogInformation("Creating Employee..."); _context.Employees.Add(Mapper.Map <Employee>(employee)); _context.SaveChanges(); _logger.LogInformation("Successfully created new employee."); return(Mapper.Map <EmployeeViewModel>(employee)); }
//This is the Action that clicking the "Add to favorites" link redirects to. Gets the result ID from the view as route data public IActionResult AddFromSearch(string id) { //Gets query parameters from TempData string country = TempData["country"].ToString(); int page = int.Parse(TempData["page"].ToString()); string what = TempData["what"].ToString(); string where = TempData["where"].ToString(); Rootobject r = jd.SearchJobs(country, page, what, where); List <Result> jobResults = r.results.ToList(); //Gets the job result matching the id passed back to the controller List <Result> toSave = jobResults.Where(x => x.id.Contains(id)).ToList(); Job saved = Job.ToJob(toSave[0]); saved.UserId = User.FindFirst(ClaimTypes.NameIdentifier).Value; //Adds job to DB and saves _context.Jobs.Add(saved); _context.SaveChanges(); //After saving, removes duplicate results from the list to display if (User.Identity.IsAuthenticated) { //Get link property of all the users saved jobs List <string> dbJobLinks = _context.Jobs.Where(x => x.UserId == User.FindFirst(ClaimTypes.NameIdentifier).Value).Select(x => x.Link).ToList(); dbJobLinks = dbJobLinks.Where(x => x != null).ToList(); List <Result> duplicates = new List <Result>(); //Adds duplicate results into a list foreach (Result result in jobResults) { if (dbJobLinks.Any(x => TextHelper.CompareJobUrl(x, result.redirect_url))) { duplicates.Add(result); } } //Removes duplicates from main list to display foreach (Result rd in duplicates) { jobResults.Remove(rd); } } //Stores query parameters in TempData for paging TempData["country"] = country; TempData["page"] = page; TempData["what"] = what; TempData["where"] = where; return(View("Search", jobResults)); }
public ActionResult Create([Bind(Include = "id,name,email")] Customer customer) { if (ModelState.IsValid) { db.Customers.Add(customer); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(customer)); }
public ActionResult Create([Bind(Include = "id,custID,orderDate")] Order order) { if (ModelState.IsValid) { db.Orders.Add(order); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.custID = new SelectList(db.Customers, "id", "name", order.custID); return(View(order)); }
public ActionResult Create([Bind(Include = "rentID,menuID,qtyOrdered,orderDueDate")] OrderDetails orderDetails) { if (ModelState.IsValid) { db.OrderDetails.Add(orderDetails); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.menuID = new SelectList(db.RestaurantMenus, "id", "item", orderDetails.menuID); ViewBag.rentID = new SelectList(db.Orders, "id", "id", orderDetails.rentID); return(View(orderDetails)); }
public async Task <IActionResult> Index(long?id) { var prjpac = (from m in _context.Package join sem in _context.Project on m.ProjectId equals sem.Id where m.Id == id select(sem.Progress + m.Value)).FirstOrDefault(); var prid = (from m in _context.Package join sem in _context.Project on m.ProjectId equals sem.Id where m.Id == id select m.ProjectId).FirstOrDefault(); var result = (from p in _context.Project where p.Id == prid select p).SingleOrDefault(); result.Progress = prjpac; _context.SaveChanges(); //SqlCommand comm = new SqlCommand("UPDATE Project SET Progress=@goal WHERE Id==@id"); //comm.Parameters.AddWithValue("@goal", prjpac); //comm.Parameters.AddWithValue("@id", prid); return(RedirectToAction("Index", "Projects")); //var finalProjectContext = _context.Project.Include(p => p.Category).Include(p => p.Person); //return View("~/Views/ProjectsAll/Index.cshtml", await finalProjectContext.ToListAsync()); //return RedirectToAction("Index", new { id = _context.Project.Id }); //return View("~/Views/ProjectsAll/Index.cshtml"); }
public static void AddUser(User user) { using (var db = new FinalProjectContext()) { db.Add(user); db.SaveChanges(); } }
public IActionResult EditUserProfile(AspNetUser a, bool IsPrivate) { if (ModelState.IsValid) { if (IsPrivate == false) { a.IsPrivate = false; } else { a.IsPrivate = true; } _context.AspNetUsers.Update(a); _context.SaveChanges(); } if (a.UserSkills.Count <= 0) { return(RedirectToAction("Skills")); } else { return(RedirectToAction("User")); } }
public void OnPost() { Book = _context.Book .Find(6); Book.NumberOfBooksAvailable = Book.NumberOfBooksAvailable + 1; _context.SaveChanges(); }
public void OnPost() { Book = _context.Book.Find(CheckoutForm.BookId); if (Book.NumberOfBooksAvailable > 0) { Book.NumberOfBooksAvailable = Book.NumberOfBooksAvailable + 1; } _context.SaveChanges(); }
public IActionResult AddSoftware(int id, int sId) { var professor = _context.Professors .Include(t => t.NeededSoftware) .Single(t => t.ProfessorID == id); var software = _context.Software.Single(s => s.SoftwareID == sId); professor.NeededSoftware.Add(new ProfessorSoftware { Professor = professor, Software = software }); try { _context.SaveChanges(); } catch (Exception e) { return(View(e)); } return(Redirect($"/Professors/Details/{id}")); }
public IActionResult SendMessage(string receiverId, string message) { Chat newChat = new Chat(); newChat.Sender = User.FindFirst(ClaimTypes.NameIdentifier).Value; newChat.Receiver = receiverId; newChat.Message = message; newChat.TimeStamp = DateTime.Now; _context.Chats.Add(newChat); _context.SaveChanges(); TempData["senderId"] = User.FindFirst(ClaimTypes.NameIdentifier).Value; TempData["receiverId"] = receiverId; List <Chat> myMessages = _context.Chats.Where(x => x.Sender == User.FindFirst(ClaimTypes.NameIdentifier).Value&& x.Receiver == receiverId).ToList(); List <Chat> theirMessages = _context.Chats.Where(x => x.Sender == receiverId && x.Receiver == User.FindFirst(ClaimTypes.NameIdentifier).Value).ToList(); myMessages.AddRange(theirMessages); myMessages = myMessages.OrderBy(x => x.Id).ToList(); return(RedirectToAction("Chat", "Chat", new { receiverId = receiverId })); }
public IActionResult Detail(int id, int pId) { var software = _context.Software .Include(t => t.NeededBy) .Single(t => t.SoftwareID == id); var professor = _context.Professors.Single(p => p.ProfessorID == pId); software.NeededBy.Add(new ProfessorSoftware { Software = software, Professor = professor }); try { _context.SaveChanges(); } catch (Exception e) { return(View(e)); } return(Redirect($"/Software/Details/{id}")); }
public IActionResult AddSoftware(int id, int sId) { var cssystem = _context.CSSystems .Include(t => t.NeededSoftware) .Single(t => t.CSSystemID == id); var software = _context.Software.Single(s => s.SoftwareID == sId); cssystem.NeededSoftware.Add(new SystemSoftware { CSSystem = cssystem, Software = software }); try { _context.SaveChanges(); } catch (Exception e) { return(View(e)); } return(Redirect($"/CSSystems/Details/{id}")); }
public OperationController(FinalProjectContext context) { _context = context; _repo = new OperationRepository(_context); if (_context.Operations.Count() == 0) { TimeSpan span = new TimeSpan(0, 0, 0, 30, 50); _context.Operations.Add(new Operation { Name = "Method Test1", ExecutionDate = DateTime.Now, ExecutionTime = span }); _context.SaveChanges(); } }
public static List <User> GetUsers() { List <User> users = new List <User>(); using (var db = new FinalProjectContext()) { var collection = db.Users; foreach (User item in collection) { users.Add(item); } db.SaveChanges(); } return(users); }
public static List <Drug> GetDrugs() { List <Drug> drugs = new List <Drug>(); using (var db = new FinalProjectContext()) { var collection = db.Drugs.Include(t => t.User); foreach (Drug item in collection) { drugs.Add(item); } db.SaveChanges(); } return(drugs); }
public IActionResult OnPost() { Contractor = _context.Contractor.Find(SetContractorStatus.ContractorId); if (!ModelState.IsValid) { return(Page()); } Contractor.WorkStatus = SetContractorStatus.status; Contractor.ActualEndDate = SetContractorStatus.EndDate; _context.SaveChanges(); return(RedirectToPage("/Contractors/Index")); }
public static void AddDrug(Drug drug, int userId) { using (var db = new FinalProjectContext()) { var users = db.Users. Where(x => (x.UserId == userId)); List <User> users__ = new List <User>(); foreach (User x in users) { users__.Add(x); } User user = users__.ElementAt(0); drug.Time = DateTime.Now; drug.User = user; db.Add(drug); db.SaveChanges(); } }
public IActionResult OnPost() { Project = _context.Project.Find(EndProject.ProjectId); Contractor = _context.Contractor.Where(b => b.ProjectID == EndProject.ProjectId).ToList(); if (!ModelState.IsValid) { return(Page()); } foreach (var contrac in Contractor) { contrac.ActualEndDate = EndProject.EndDate; contrac.WorkStatus = "no allocation"; } Project.ActualEndDate = EndProject.EndDate; _context.SaveChanges(); return(RedirectToPage("/Projects/Index")); }
public IActionResult OnPost(int id) { UserBook = _context.UserBook .Where(y => y.BookId.Equals(id)).FirstOrDefault(); Book = _context.Book .Where(x => x.Id.Equals(id)).FirstOrDefault(); var userbook = new UserBook(); userbook.BookId = UserBook.BookId; userbook.Book = UserBook.Book; userbook.CheckInDate = UserBook.CheckInDate; userbook.CheckoutDate = UserBook.CheckoutDate; userbook.FeeAmount = UserBook.FeeAmount; userbook.User = UserBook.User; userbook.UserId = UserBook.UserId; userbook.Rating = UserBook.Rating; var book = new Book(); book = _context.Book.Find(userbook.BookId); book.NumberOfBooksAvailable -= 1; _context.SaveChanges(); return RedirectToPage("/UserBookProfile"); }
public static void Initialize(IServiceProvider serviceProvider) { using (var context = new FinalProjectContext( serviceProvider.GetRequiredService <DbContextOptions <FinalProjectContext> >())) { // Look for any movies. if (context.Movies.Any() || context.Categories.Any() || context.Users.Any()) { return; // DB has been seeded } context.Users.AddRange( new User { CreatedDate = DateTime.Now, ModifiedDate = DateTime.Now, IsDeleted = false, IsActivated = true, IsAdmin = true, Email = "*****@*****.**", Password = "******", Name = "Admin", Phone = "087812345678" }, new User { CreatedDate = DateTime.Now, ModifiedDate = DateTime.Now, IsDeleted = false, IsActivated = true, IsAdmin = true, Email = "*****@*****.**", Password = "******", Name = "Admin 2", Phone = "087812345678" }, new User { CreatedDate = DateTime.Now, ModifiedDate = DateTime.Now, IsDeleted = false, IsActivated = true, IsAdmin = false, Email = "*****@*****.**", Password = "******", Name = "User", Phone = "087812345678" }, new User { CreatedDate = DateTime.Now, ModifiedDate = DateTime.Now, IsDeleted = false, IsActivated = true, IsAdmin = false, Email = "*****@*****.**", Password = "******", Name = "User 2", Phone = "087812345678" } ); context.Categories.AddRange( new Category { CreatedDate = DateTime.Now, ModifiedDate = DateTime.Now, IsDeleted = false, Name = "Action" }, new Category { CreatedDate = DateTime.Now, ModifiedDate = DateTime.Now, IsDeleted = false, Name = "Biography" }, new Category { CreatedDate = DateTime.Now, ModifiedDate = DateTime.Now, IsDeleted = false, Name = "Family" }, new Category { CreatedDate = DateTime.Now, ModifiedDate = DateTime.Now, IsDeleted = false, Name = "Horror" }, new Category { CreatedDate = DateTime.Now, ModifiedDate = DateTime.Now, IsDeleted = false, Name = "Romance" }, new Category { CreatedDate = DateTime.Now, ModifiedDate = DateTime.Now, IsDeleted = false, Name = "Thriller" }, new Category { CreatedDate = DateTime.Now, ModifiedDate = DateTime.Now, IsDeleted = false, Name = "Fantasy" }, new Category { CreatedDate = DateTime.Now, ModifiedDate = DateTime.Now, IsDeleted = false, Name = "Adventure" }, new Category { CreatedDate = DateTime.Now, ModifiedDate = DateTime.Now, IsDeleted = false, Name = "Comedy" }, new Category { CreatedDate = DateTime.Now, ModifiedDate = DateTime.Now, IsDeleted = false, Name = "Animation" }, new Category { CreatedDate = DateTime.Now, ModifiedDate = DateTime.Now, IsDeleted = false, Name = "Drama" }, new Category { CreatedDate = DateTime.Now, ModifiedDate = DateTime.Now, IsDeleted = false, Name = "History" }, new Category { CreatedDate = DateTime.Now, ModifiedDate = DateTime.Now, IsDeleted = false, Name = "Musical" } ); context.SaveChanges(); context.Movies.AddRange( new Movie { CreatedDate = DateTime.Now, ModifiedDate = DateTime.Now, IsDeleted = false, Title = "Disney Moana", Viewed = 0, Released = new DateTime(2016, 11, 25), Description = "An adventurous teenager sails out on a daring mission to save her people. During her journey, Moana meets the once-mighty demigod Maui, who guides her in her quest to become a master way-finder. Together they sail across the open ocean on an action-packed voyage, encountering enormous monsters and impossible odds. Along the way, Moana fulfills the ancient quest of her ancestors and discovers the one thing she always sought: her own identity.", BackgroundUrl = "b1.jpg", ThumbnailUrl = "c1.jpg", Category = new Category { Id = 3 } }, new Movie { CreatedDate = DateTime.Now, ModifiedDate = DateTime.Now, IsDeleted = false, Title = "Dirty Grandpa", Viewed = 0, Released = new DateTime(2016, 1, 21), Description = "Uptight lawyer Jason Kelly (Zac Efron) is one week away from marrying his boss's controlling daughter, putting him on the fast track for a partnership at his firm. Tricked by his grandfather Dick (Robert De Niro), Jason finds himself driving the foulmouthed old man to Daytona Beach, Fla., for a wild spring break that includes frat parties, bar fights and an epic night of karaoke. While Jason worries about the upcoming wedding, Dick tries to show his grandson how to live life to the fullest.", BackgroundUrl = "b2.jpg", ThumbnailUrl = "c2.jpg", Category = new Category { Id = 4 } }, new Movie { CreatedDate = DateTime.Now, ModifiedDate = DateTime.Now, IsDeleted = false, Title = "Ride Along 2", Viewed = 0, Released = new DateTime(2016, 1, 6), Description = "Rookie lawman Ben Barber (Kevin Hart) aspires to become a detective like James Payton (Ice Cube), his future brother-in-law. James reluctantly takes Ben to Miami to follow up on a lead that's connected to a drug ring. The case brings them to a homicide detective and a computer hacker who reveals evidence that implicates a respected businessman. It's now up to James and Ben to prove that charismatic executive Antonio Pope is actually a violent crime lord who rules southern Florida's drug trade.", BackgroundUrl = "b3.jpg", ThumbnailUrl = "c3.jpg", Category = new Category { Id = 12 } }, new Movie { CreatedDate = DateTime.Now, ModifiedDate = DateTime.Now, IsDeleted = false, Title = "Keanu", Viewed = 0, Released = new DateTime(2016, 4, 29), Description = "Recently dumped by his girlfriend, slacker Rell (Jordan Peele) finds some happiness when a cute kitten winds up on his doorstep. After a heartless thief steals the cat, Rell recruits his cousin Clarence (Keegan-Michael Key) to help him retrieve it. They soon learn that a thug named Cheddar (Method Man) has the animal, and he'll only give it back if the two men agree to work for him. Armed with guns and a gangster attitude, it doesn't take long for the hapless duo to land in big trouble.", BackgroundUrl = "b5.jpg", ThumbnailUrl = "c5.jpg", Category = new Category { Id = 12 } }, new Movie { CreatedDate = DateTime.Now, ModifiedDate = DateTime.Now, IsDeleted = false, Title = "Ice Age : Collision Course", Viewed = 0, Released = new DateTime(2016, 7, 29), Description = "Manny the mammoth starts to worry when his daughter Peaches announces her engagement. Still unlucky in love, Sid the sloth volunteers to plan the couple's wedding. To Manny's dismay, nothing can stop the upcoming nuptials, except maybe the end of the world. When Scrat accidentally launches himself into outer space, he sets off a chain reaction that sends an asteroid hurtling toward Earth. Now, the entire herd must leave home to explore new lands and save itself from Scrat's cosmic blunder.", BackgroundUrl = "b6.jpg", ThumbnailUrl = "c6.jpg", Category = new Category { Id = 6 } }, new Movie { CreatedDate = DateTime.Now, ModifiedDate = DateTime.Now, IsDeleted = false, Title = "Mike and Dave Need Wedding Dates", Viewed = 0, Released = new DateTime(2016, 6, 30), Description = "Mike and Dave Stangle are young, adventurous, fun-loving brothers who tend to get out of control at family gatherings. When their sister Jeanie reveals her Hawaiian wedding plans, the rest of the clan insists that they both bring respectable dates. After placing an ad on Craigslist, the siblings decide to pick Tatiana and Alice, two charming and seemingly normal women. Once they arrive on the island, however, Mike and Dave realize that their companions are ready to get wild and party hard.", BackgroundUrl = "b7.jpg", ThumbnailUrl = "c7.jpg", Category = new Category { Id = 1 } }, new Movie { CreatedDate = DateTime.Now, ModifiedDate = DateTime.Now, IsDeleted = false, Title = "Bad Moms", Viewed = 0, Released = new DateTime(2016, 9, 14), Description = "Amy (Mila Kunis) has a great husband, overachieving children, beautiful home and successful career. Unfortunately, she's also overworked, exhausted and ready to snap. Fed up, she joins forces with two other stressed-out mothers (Kristen Bell, Kathryn Hahn) to get away from daily life and conventional responsibilities. As the gals go wild with their newfound freedom, they set themselves up for the ultimate showdown with PTA queen bee Gwendolyn and her clique of seemingly perfect moms.", BackgroundUrl = "b8.jpg", ThumbnailUrl = "c8.jpg", Category = new Category { Id = 4 } }, new Movie { CreatedDate = DateTime.Now, ModifiedDate = DateTime.Now, IsDeleted = false, Title = "Barbershop: The Next Cut", Viewed = 0, Released = new DateTime(2016, 4, 15), Description = "AmyTo survive harsh economic times, Calvin and Angie have merged the barbershop and beauty salon into one business. The days of male bonding are gone as Eddie and the crew must now contend with sassy female co-workers and spirited clientele. As the battle of the sexes rages on, a different kind of conflict has taken over Chicago. Crime and gangs are on the rise, leaving Calvin worried about the fate of his son. Together, the friends come up with a bold plan to take back their beloved neighborhood.", BackgroundUrl = "b9.jpg", ThumbnailUrl = "c9.jpg", Category = new Category { Id = 2 } }, new Movie { CreatedDate = DateTime.Now, ModifiedDate = DateTime.Now, IsDeleted = false, Title = "Nine Lives", Viewed = 0, Released = new DateTime(2016, 11, 25), Description = "Tom Brand (Kevin Spacey) is a billionaire whose workaholic lifestyle takes him away from his loving wife Lara and adorable daughter Rebecca. Needing a present for Rebecca's 11th birthday, Brand buys a seemingly harmless cat from a mysterious pet store. Suddenly, a bizarre turn of events traps poor Tom inside the animal's body. The owner of the business tells him that he has one week to reconnect with his family, or live out the rest of his days as a cute and furry feline named Mr. Fuzzypants.", BackgroundUrl = "b10.jpg", ThumbnailUrl = "c10.jpg", Category = new Category { Id = 6 } }, new Movie { CreatedDate = DateTime.Now, ModifiedDate = DateTime.Now, IsDeleted = false, Title = "Billy Lynn's Long Halftime Walk", Viewed = 0, Released = new DateTime(2016, 11, 9), Description = "Nineteen-year-old private Billy Lynn (Joe Alwyn), along with his fellow soldiers in Bravo Squad, becomes a hero after a harrowing Iraq battle and is brought home temporarily for a victory tour. Through flashbacks, culminating at the spectacular halftime show of the Thanksgiving Day football game, what really happened to the squad is revealed, contrasting the realities of the war with America's perceptions. Based on the novel by Ben Fountain.", BackgroundUrl = "b11.jpg", ThumbnailUrl = "c11.jpg", Category = new Category { Id = 8 } }, new Movie { CreatedDate = DateTime.Now, ModifiedDate = DateTime.Now, IsDeleted = false, Title = "War on Everyone", Viewed = 0, Released = new DateTime(2016, 11, 3), Description = "Two corrupt cops, who make money blackmailing criminals, come up against one who may be far more dangerous than both of them.", BackgroundUrl = "b12.jpg", ThumbnailUrl = "c12.jpg", Category = new Category { Id = 12 } }, new Movie { CreatedDate = DateTime.Now, ModifiedDate = DateTime.Now, IsDeleted = false, Title = "Before I Wake", Viewed = 0, Released = new DateTime(2016, 11, 12), Description = "Foster parents Mark and Jessie welcome 8-year-old Cody into their home. The boy tells Jessie that he's terrified to fall asleep, but she assumes it's just a natural fear for any young child. The couple become startled when their dead biological son suddenly appears in their living room. To their surprise, Cody's dreams can magically become real but so can his nightmares. Mark and Jessie must now uncover the truth behind Cody's mysterious ability before his imagination harms them all.", BackgroundUrl = "b13.jpg", ThumbnailUrl = "c13.jpg", Category = new Category { Id = 2 } } ); context.SaveChanges(); } }
public void Save() { _context.SaveChanges(); }