//Se elimina una ciudad de la lista de ciudades del usuario public ActionResult RemoveUserCity(string location, string userID) { int IntUserID = Int32.Parse(userID); UserCity userCity = db.UserCities.Where(i => i.UserID == IntUserID && i.Location == location).FirstOrDefault(); db.UserCities.Remove(userCity); db.SaveChanges(); return(Json(new { removelocation = location })); }
public async Task <IActionResult> Create([Bind("UserId,CityId")] UserCity userCity) { var usrCt = _context.UsersCities.Where(p => p.UserId == userCity.UserId).Where(m => m.CityId == userCity.CityId); // проверка на дубликат if (usrCt.Count() == 0) { if (ModelState.IsValid) { _context.Add(userCity); await _context.SaveChangesAsync(); return(Ok()); } } return(BadRequest()); }
public async Task <IActionResult> DeleteConfirmed([Bind("UserId,CityId")] UserCity userCity) { UserCity[] result = new UserCity[1]; var usrCt = _context.UsersCities.Where(p => p.UserId == userCity.UserId).Where(m => m.CityId == userCity.CityId); result = usrCt.ToArray(); if (result.Count() != 0) { _context.UsersCities.Remove(result[0]); await _context.SaveChangesAsync(); return(Ok()); } else { return(NotFound()); } }
public List <UserCity> ToList(string filter, string value = null) { DataTable dt = ucd.Get(filter, value); List <UserCity> lst = new List <UserCity>(); if (dt.Rows.Count > 0) { for (int i = 0; i < dt.Rows.Count; i++) { UserCity Client = new UserCity(); Client.CityId = int.Parse(dt.Rows[i]["CityId"].ToString()); Client.CityName = dt.Rows[i]["CityName"].ToString(); lst.Add(Client); } } return(lst); }
//El usuario agrega una ciudad a su lista de ciudades public ActionResult AddUserCity(string cityName, string userID) { int userIDInt = Int32.Parse(userID); var cityAlreadySaved = db.UserCities.Where(i => i.UserID == userIDInt && i.Location == cityName); if (cityAlreadySaved != null) { UserCity userCity = new UserCity { UserID = Int32.Parse(userID), Location = cityName }; db.UserCities.Add(userCity); db.SaveChanges(); return(Json(new { message = "ok" })); } else { return(Json(new { message = "error" })); } }
public async Task CreateStartUpCity(string userId, string name, string avatar, int runeId) { var city = new City() { Avatar = avatar, Name = name, Barracks = new Barracks { Level = 1, Description = "This is barracks!", SilverPrice = 12, StonePrice = 16, WoodPrice = 16, TrainingLimit = 100 }, DefenceWall = new DefenceWall { Level = 1, Description = "This is a defence wall!", SilverPrice = 12, StonePrice = 24, WoodPrice = 8, Defence = 1000 }, Farm = new Farm { Level = 1, Description = "This is a farm!", FoodProduction = 100, SilverPrice = 13, StonePrice = 8, WoodPrice = 12 }, House = new House { Level = 1, Description = "This is a house!", WorkerLimit = 100, SilverPrice = 10, StonePrice = 15, WoodPrice = 15, Production = 4 }, Marketplace = new Marketplace { Level = 1, Description = "This is a marketplace!", SilverPrice = 10, StonePrice = 15, WoodPrice = 15 }, WoodMine = new WoodMine { Level = 1, Description = "This is a woodmine!", Production = 100, SilverPrice = 10, StonePrice = 12, WoodPrice = 13 }, StoneMine = new StoneMine { Level = 1, Description = "This is a stone mine!", Production = 100, SilverPrice = 10, StonePrice = 35, WoodPrice = 12 }, TownHall = new TownHall { Level = 1, Description = "This is a townhall!", SilverPrice = 11, StonePrice = 14, WoodPrice = 14, ArmyLimit = 250 }, Archers = new Archers { Attack = 1000, Defence = 1000, Health = 1000, Count = 11, }, Infantry = new Infantry { Attack = 1000, Defence = 1000, Health = 1000, Count = 11 }, Cavalry = new Cavalry { Attack = 1000, Defence = 1000, Health = 1000, Count = 11 }, Artillery = new Artillery { Attack = 1000, Defence = 1000, Health = 1000, Count = 11 }, RuneId = runeId, Silver = 1000, Stone = 100, Wood = 100, Food = 200, Workers = 50, Gold = 10, }; ////var user = await this.userService.GetUserById(userId); await this.cityRepo.AddAsync(city); await this.cityRepo.SaveChangesAsync(); city.Archers.CityId = city.Id; city.Artillery.CityId = city.Id; city.Cavalry.CityId = city.Id; city.Infantry.CityId = city.Id; await this.cityRepo.SaveChangesAsync(); var userCity = new UserCity() { UserId = userId, CityId = city.Id }; await this.userCityRepo.AddAsync(userCity); await this.userCityRepo.SaveChangesAsync(); }