Exemplo n.º 1
0
 /// <summary>
 /// Remove the city from FavoriteCity table.
 /// </summary>
 /// <param name="city"></param>
 /// <returns></returns>
 public bool DeleteFavorite(FavoriteCity city)
 {
     using (_context = new WeatherDBContext())
     {
         FavoriteCity favorite = _context.FavoriteCity.Find(city.Id);
         if (favorite != null)
         {
             _context.FavoriteCity.Remove(favorite);
             _context.SaveChanges();
             return(true);
         }
         else
         {
             return(false);
         }
     }
 }
Exemplo n.º 2
0
        /// <summary>
        /// The method adds city to FavoriteCity table.
        /// </summary>
        /// <param name="city"></param>
        /// <returns></returns>
        public Response AddFavorite(FavoriteCity city)
        {
            Response response = new Response();

            using (_context = new WeatherDBContext())
            {
                FavoriteCity favorite = _context.FavoriteCity.Where(l => l.Key == city.Key).Select(m => m).FirstOrDefault();
                if (favorite == null)
                {
                    _context.FavoriteCity.Add(city);
                    _context.SaveChanges();

                    response.ErrorCode = 0;
                    response.Message   = "Favorite city was added successfully!";
                }
                else
                {
                    response.ErrorCode = 1;
                    response.Message   = "The favorite city already exists in the database !";
                }
            }

            return(response);
        }