public IActionResult AddGroup(string groupName) { Group newGroup = new Group(); AspNetUsers thisUser = _context.AspNetUsers.Where(u => u.UserName == User.Identity.Name).First(); var groupList = _context.Group.Where(u => u.UserId == thisUser.Id).ToList(); List <string> groupNames = new List <string>(); foreach (var item in groupList) { groupNames.Add(item.GroupName); } if (groupNames.Contains(groupName)) { ViewData["Name"] = groupName; return(RedirectToAction("ListGroups")); } else { newGroup.GroupName = groupName; newGroup.UserId = thisUser.Id; _context.Group.Add(newGroup); _context.SaveChanges(); return(RedirectToAction("DisplayGroups")); } }
public IActionResult AddToFavorites(Meal item) { FavoriteRecipes newFavorite = new FavoriteRecipes(); AspNetUsers thisUser = _context.AspNetUsers.Where(u => u.UserName == User.Identity.Name).First(); var favList = _context.FavoriteRecipes.Where(u => u.UserId == thisUser.Id).ToList(); List <string> mealIdList = new List <string>(); foreach (var meal in favList) { mealIdList.Add(meal.RecipeId); } if (mealIdList.Contains(item.idMeal)) { return(RedirectToAction("DisplayFavorite")); } else { newFavorite.UserId = thisUser.Id; newFavorite.RecipeId = item.idMeal; newFavorite.RecipeImage = item.strMealThumb; newFavorite.RecipeName = item.strMeal; if (ModelState.IsValid) { _context.FavoriteRecipes.Add(newFavorite); _context.SaveChanges(); return(RedirectToAction("DisplayFavorite")); } return(View(item)); } }
public IActionResult AddFriend(AspNetUsers user) { Friends newFriend = new Friends(); AspNetUsers thisUser = _context.AspNetUsers.Where(u => u.UserName == User.Identity.Name).First(); var favList = _context.Friends.Where(u => u.UserId == thisUser.Id).ToList(); List <string> friendIdList = new List <string>(); foreach (var friend in favList) { friendIdList.Add(friend.FriendId); } if (friendIdList.Contains(user.Id)) { return(View()); } else { newFriend.UserId = thisUser.Id; newFriend.FriendId = user.Id; } if (ModelState.IsValid) { _context.Friends.Add(newFriend); _context.SaveChanges(); return(RedirectToAction("ViewFriends")); } return(View(user)); }
public async Task <IActionResult> AddProjectClientParticipant(EditProjectDetailViewModel model) { if (ModelState.IsValid) { //ViewData["theid"] = model.ProjectID; try{ var ProjectId = model.ProjectID; var project = await _context.Projects.SingleOrDefaultAsync(m => m.ID == ProjectId); var ClientId = model.SelectedID; var client = await _context.Clients.SingleOrDefaultAsync(m => m.ID == ClientId); ProjectRoster participant = new ProjectRoster { ProjectID = ProjectId, Project = project, ParticipantID = ClientId, Participant = client }; _context.ProjectRoster.Add(participant); _context.SaveChanges(); } catch (Exception exp) { throw(exp); } return(RedirectToAction(nameof(Details), new { id = model.ProjectID })); } return(View()); }
public ActionResult Create([Bind(Include = "ExpenseInId,Description,Amount,CreatedBy")] ExpenseIn expenseIn) { if (ModelState.IsValid) { db.Inbound.Add(expenseIn); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(expenseIn)); }
public IActionResult PostApartment([FromBody] Apartment apartment) { var result = Manager.ValidateApartment(apartment); if (result == "success") { database.Apartments.Add(apartment); database.SaveChanges(); var query = database.Apartments .AsQueryable(); return(Ok(query.ToList())); } else { return(BadRequest(result)); } }
public IActionResult EditPreferences(string milk, string eggs, string fish, string shellfish, string treenuts, string peanuts, string soy, string wheat, string diet, string privacy) { AspNetUsers thisUser = _context.AspNetUsers.Where(u => u.UserName == User.Identity.Name).First(); if (milk == "milk") { thisUser.Milk = true; } else { thisUser.Milk = false; } if (eggs == "eggs") { thisUser.Eggs = true; } else { thisUser.Eggs = false; } if (fish == "fish") { thisUser.Fish = true; } else { thisUser.Fish = false; } if (shellfish == "shellfish") { thisUser.Shellfish = true; } else { thisUser.Shellfish = false; } if (treenuts == "treenuts") { thisUser.Treenuts = true; } else { thisUser.Treenuts = false; } if (peanuts == "peanuts") { thisUser.Peanuts = true; } else { thisUser.Peanuts = false; } if (soy == "soy") { thisUser.Soy = true; } else { thisUser.Soy = false; } if (wheat == "wheat") { thisUser.Wheat = true; } else { thisUser.Wheat = false; } if (diet == "none") { thisUser.Diet = null; } else { thisUser.Diet = diet; } if (privacy == "private") { thisUser.Private = true; } else if (privacy == "public") { thisUser.Private = false; } _context.Entry(thisUser).State = Microsoft.EntityFrameworkCore.EntityState.Modified; _context.SaveChanges(); return(RedirectToAction("Userpage")); }
public IActionResult PostOrder([FromQuery] string ids, [FromQuery] int clientId, [FromBody] Order o) { var orders = new List <Order>(); foreach (var i in ids.Split(",")) { var id = Convert.ToInt32(i); var order = new Order(); var apartment = database.Apartments.FirstOrDefault(x => x.Id == id);; var client = database.Clients.FirstOrDefault(x => x.Id == clientId); order.ApartmentId = id; order.ClientId = clientId; var result = Manager.ValidateOrder(order, database.Clients.ToList(), database.Apartments.ToList()); if (result == "success") { order.Region = apartment.RegionId; if (apartment.RegionId == "Медеуский") { order.Cost = Convert.ToInt64(apartment.Cost * 1.12); } else if (apartment.RegionId == "Алмалинский") { order.Cost = Convert.ToInt64(apartment.Cost * 1.11); } else if (apartment.RegionId == "Бостандыкский") { order.Cost = Convert.ToInt64(apartment.Cost * 1.1); } else if (apartment.RegionId == "Наурызбайский") { order.Cost = Convert.ToInt64(apartment.Cost * 1.09); } else if (apartment.RegionId == "Алатауский") { order.Cost = Convert.ToInt64(apartment.Cost * 1.08); } else if (apartment.RegionId == "Ауэзовский") { order.Cost = Convert.ToInt64(apartment.Cost * 1.07); } else if (apartment.RegionId == "Жетысуский") { order.Cost = Convert.ToInt64(apartment.Cost * 1.06); } else { order.Cost = Convert.ToInt64(apartment.Cost * 1.05); } orders.Add(order); } else { return(BadRequest(result)); } } string reg = orders[0].Region; int cnt = 0; foreach (var order in orders) { if (order.Region == reg) { cnt += 0; } else { cnt++; } } if (cnt == 0) { foreach (var order in orders) { database.Orders.Add(order); } database.SaveChanges(); var query = database.Orders .AsQueryable(); return(Ok(query)); } else { return(BadRequest("Apartments not from one region")); } }