/// <summary> /// 增加一条数据 /// </summary> public int Add(FavoriteModel model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into tb_Favorite("); strSql.Append("ProductId,UserId)"); strSql.Append(" values ("); strSql.Append("@ProductId,@UserId)"); strSql.Append(";select @@IDENTITY"); SqlParameter[] parameters = { new SqlParameter("@ProductId", SqlDbType.Int, 4), new SqlParameter("@UserId", SqlDbType.Int, 4) }; parameters[0].Value = model.ProductId; parameters[1].Value = model.UserId; object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters); if (obj == null) { return(0); } else { return(Convert.ToInt32(obj)); } }
public IList <FavoriteModel> GetFavorites() { List <FavoriteModel> output = new List <FavoriteModel>(); try { // Create a new connection object using (SqlConnection conn = new SqlConnection(connectionString)) { // Open the connection conn.Open(); string sql = "select survey_result.parkCode, park.parkName, Count(survey_result.parkCode) AS 'Count' from survey_result join park on park.parkCode = survey_result.parkCode group by survey_result.parkCode, park.parkName order by count(survey_result.parkCode) desc, park.parkName"; SqlCommand cmd = new SqlCommand(sql, conn); // Execute the command SqlDataReader reader = cmd.ExecuteReader(); while (reader.Read()) { FavoriteModel favorite = RowToObject(reader); output.Add(favorite); } } } catch (SqlException ex) { throw; } return(output); }
public static List <FavoriteModel> GetListByUid(int uid, int pageSize, int pageIndex, out int totalcount) { int start = (pageIndex - 1) * pageSize; string sql = string.Format("select * from odnshop_favorite where uid={0} order by fid desc limit {1},{2}", uid.ToString(), start, pageSize); List <FavoriteModel> list = new List <FavoriteModel>(); DataTable dt = MySqlDbHelper.Query(sql).Tables[0]; FavoriteModel info = null; foreach (DataRow dr in dt.Rows) { info = new FavoriteModel(); info.product = (ProductModel)SerializeHelper.LoadFromXml(new ProductModel().GetType(), dr["productxml"].ToString()); info.fid = Int32.Parse(dr["fid"].ToString()); info.uid = Int32.Parse(dr["uid"].ToString()); info.productid = Int32.Parse(dr["productid"].ToString()); info.createtime = DateTime.Parse(dr["createtime"].ToString()); list.Add(info); } totalcount = MySqlDbHelper.ExecuteScalar("select count(*) from odnshop_favorite where uid=" + uid); return(list); }
public async Task <IActionResult> OnPostFollow(int?showId) { if (showId == null) { return(NotFound()); } var user = await GetUserModel(); if (user != null) { var favorite = new FavoriteModel() { ShowId = (int)showId }; if (!IsFollow) { user.Favorites.Add(favorite); context.Users.Update(user); context.SaveChanges(); } } return(RedirectToPage("/More", new { id = showId })); }
/// <summary>Saves a favorite to the favorite list</summary> /// <param name="isMale">Whether the player is male</param> /// <param name="baseIndex">The base index</param> /// <param name="skinIndex">The skin index</param> /// <param name="hairIndex">The hair index</param> /// <param name="faceIndex">The face index</param> /// <param name="noseIndex">The nose index</param> /// <param name="shoesIndex">The shoes index</param> /// <param name="accessoryIndex">The accessory index</param> /// <param name="isBald">Whether the player is bald</param> public void SaveFavoriteToList(bool isMale, int baseIndex, int skinIndex, int hairIndex, int faceIndex, int noseIndex, int shoesIndex, int accessoryIndex, bool isBald) { //Set all the stuff FavoriteModel favModel = new FavoriteModel(); favModel.IsDefault = false; favModel.IsMale = isMale; favModel.BaseIndex = baseIndex; favModel.SkinIndex = skinIndex; favModel.HairIndex = hairIndex; favModel.FaceIndex = faceIndex; favModel.NoseIndex = noseIndex; favModel.ShoeIndex = shoesIndex; favModel.AccessoryIndex = accessoryIndex; favModel.IsBald = isBald; favModel.EyeColor = Game1.player.newEyeColor.Value; favModel.HairColor = Game1.player.hairstyleColor.Value; //Check if there is an emtpy spot in the favorites list for (int i = 0; i < 40; i++) { if (Favorites[i].IsDefault) { Entry.Monitor.Log("Adding Favorite to list.", LogLevel.Trace); Favorites[i] = favModel; return; } else if (i == 39 && !Favorites[i].IsDefault) { Entry.Monitor.Log("Reached the maximum amount of favorites, try deleting some.", LogLevel.Warn); return; } } }
public IActionResult Post([FromBody] FavoriteDto favoriteDto) { try { //var fave = new FavoriteModel() //{ // id = favoriteDto.Id, // favorited_id = favoriteDto.FavoritedUrl, // user_id = favoriteDto.UserId //}; var favoriteModel = new FavoriteModel(); favoriteModel.id = favoriteDto.Id; favoriteModel.recipe_id = favoriteDto.RecipeId; favoriteModel.favorited_title = favoriteDto.FavoriteTitle; favoriteModel.user_id = favoriteDto.UserId; _favoriteRepository.Insert(favoriteModel); } catch (Exception ex) { return(BadRequest(ex.Message)); } return(Ok()); }
/// <summary> /// Método que retorna uma coleção de mates favoritos /// do employer correspondente ao ID de parametro do método /// </summary> /// <param name="id">Id do employer que possui os mates favoritos</param> /// <returns>Coleção de Mates favoritos</returns> public Collection <FavoriteModel> FavoritesList(int id) { Collection <FavoriteModel> favorite = new Collection <FavoriteModel>(); using (SqlCommand cmd = _connection.Fetch().CreateCommand()) { cmd.CommandType = CommandType.Text; cmd.CommandText = "SELECT dbo.[User].UserName, dbo.[User].Email " + "FROM dbo.[Favourites] INNER JOIN dbo.[User] ON Favourites.MateId = dbo.[User].Id " + "WHERE EmployerId = @id"; cmd.Parameters.Add("@id", SqlDbType.Int).Value = id; using (SqlDataAdapter adapter = new SqlDataAdapter(cmd)) { DataTable table = new DataTable(); adapter.Fill(table); foreach (DataRow row in table.Rows) { FavoriteModel favoritesModel = new FavoriteModel { UserName = row["UserName"].ToString(), Email = row["Email"].ToString(), }; favorite.Add(favoritesModel); } } } return(favorite); }
public ActionResult Post(ContentReference reference) { var username = User.Identity.Name; var contentLink = reference.ToReferenceWithoutVersion().ToString(); var item = DataStore.Items <FavoriteModel>() .FirstOrDefault(model => model.UserName == username && model.ContentLink == contentLink); // Check to see if the requested contentLink already exists in the store. if (item != null) { return(Rest(item)); } // Add the new favorite to the store. item = new FavoriteModel { Id = Guid.NewGuid(), UserName = username, ContentLink = contentLink }; DataStore.Save(item); // Return the model for the new favorite. return(Rest(item)); }
/* * Action that allows a user to save an item * to view later on the MyFavorites page * */ public IActionResult SaveItem(RootobjectOsrsGe items, string returnUrl) { var url = "https://api.osrsbox.com/items?where={ \"name\": \"" + items.item.name + "\", \"duplicate\": false }"; _Items nameToId = new _Items(); nameToId = DownloadedItem.Download_serialized_json_data(url); url = "https://secure.runescape.com/m=itemdb_oldschool/api/catalogue/detail.json?item=" + nameToId.id; RootobjectOsrsGe itemID = new RootobjectOsrsGe(); itemID = DownloadedItemOsrsGe.Download_serialized_json_data(url); FavoriteModel favorite = new FavoriteModel { ItemID = itemID.item.id.ToString(), Username = HttpContext.User.Identity.Name }; if (repository.SaveFavorite(favorite) == 1) { TempData["Result"] = "Item successfully added to favorites"; return(Redirect(returnUrl)); } else if (repository.SaveFavorite(favorite) == 0) { TempData["Result"] = "This item is already in your favorites"; return(Redirect(returnUrl)); } else { TempData["Result"] = "Something went wrong with adding this item"; return(Redirect(returnUrl)); } }
/// <summary> /// 更新一条数据 /// </summary> public bool Update(FavoriteModel model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update tb_Favorite set "); strSql.Append("ProductId=@ProductId,"); strSql.Append("UserId=@UserId"); strSql.Append(" where FavoriteID=@FavoriteID"); SqlParameter[] parameters = { new SqlParameter("@ProductId", SqlDbType.Int, 4), new SqlParameter("@UserId", SqlDbType.Int, 4), new SqlParameter("@FavoriteID", SqlDbType.Int, 4) }; parameters[0].Value = model.ProductId; parameters[1].Value = model.UserId; parameters[2].Value = model.FavoriteID; int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters); if (rows > 0) { return(true); } else { return(false); } }
/* * Removes an item from the favorites page */ public IActionResult RemoveItem(_Items item) { FavoriteModel model = new FavoriteModel(); model = (repository.Items.FirstOrDefault(i => i.ItemID == item.id && i.Username == HttpContext.User.Identity.Name)); repository.DeleteFavorite(model); return(RedirectToAction("MyFavorites")); }
public int Insert(FavoriteModel favorite) { var sql = "INSERT INTO public.favorited(recipe_id, favorited_title, user_id) VALUES(@recipe_id, @favorited_title, @user_id)"; var parameters = favorite; var id = _postgreSQL.Insert(sql, parameters); return(id); }
public async Task <IActionResult> UnfavoriteGame(FavoriteModel model) { await _mediator.Send(new UnfavoriteGame { GameId = model.GameId }); return(Ok()); }
private FavoriteModel RowToObject(SqlDataReader reader) { FavoriteModel favorite = new FavoriteModel(); favorite.ParkCode = Convert.ToString(reader["parkCode"]); favorite.ParkName = Convert.ToString(reader["parkName"]); favorite.Votes = Convert.ToInt32(reader["Count"]); return(favorite); }
public IHttpActionResult delete_favorite(int id, int FavorId) { UserModel user = db.UserModels.FirstOrDefault(u => u.UserId == id); FavoriteModel favor = user.FavoriteList.FirstOrDefault(f => f.FavorId == FavorId); user.FavoriteList.Remove(favor); db.SaveChanges(); return(Ok(favor)); }
public void ProcessRequest(HttpContext context) { string customerID = context.Request.QueryString["customerID"]; string articleID = context.Request.QueryString["articleID"]; FavoriteModel model = new FavoriteModel(); model.ArticleID = Guid.Parse(articleID); model.CustomerID = Guid.Parse(customerID); bool bl = service.CreateFavorite(model); context.Response.Write(bl); }
private async Task FindFavorite() { _favorite = null; var findResult = await _client.Get <FavoriteModel>(x => x.NewsId == News.Id && x.UserId == Settings.UserId); if (string.IsNullOrWhiteSpace(findResult?.Id)) { return; } _favorite = findResult; IsFavorite = true; }
protected void Page_Load(object sender, EventArgs e) { FavoriteBll fbll = new FavoriteBll(); FavoriteModel favModel = new FavoriteModel(); favModel.ContentId = int.Parse(ReqParas["cid"]); favModel.UserId = CurrentUser.UserId; favModel.ContentType = (ContentType)int.Parse(ReqParas["ctype"]); favModel.FavoriteName = ""; favModel.FavoriteUrl = ""; fbll.Add(favModel); Response.Redirect("MyFavorite.aspx"); }
public static void Add(FavoriteModel info) { string sql = @"INSERT INTO odnshop_favorite (uid,productid,createtime,productxml) VALUES (?uid,?productid,?createtime,?productxml)"; MySqlParameter[] parameters = { MySqlDbHelper.MakeInParam("?uid", MySqlDbType.Int32, 4, info.uid), MySqlDbHelper.MakeInParam("?productid", MySqlDbType.Int32, 4, info.productid), MySqlDbHelper.MakeInParam("?createtime", MySqlDbType.Datetime, 8, info.createtime), MySqlDbHelper.MakeInParam("?productxml", MySqlDbType.VarChar, 0, SerializeHelper.SaveToString(info.product)) }; MySqlDbHelper.Query(sql, parameters); }
public IActionResult UnFavorite([FromBody] FavoriteModel favorite) { try { var user = _userRepository.GetByAuthId(favorite.UserId); _recipeRepository.UnFavoriteRecipe(favorite.RecipeId, user.Id.ToString(), true); return(Ok()); } catch (Exception e) { _logger.LogError(e, e.Message); return(StatusCode(500)); } }
public async Task <IHttpActionResult> RemoveFavorite([FromBody] FavoriteModel favoriteModel) { FavoriteRepository repository = new FavoriteRepository(); var result = await repository.RemoveFavorite(rhNetContext, this.User.Identity.Name, favoriteModel); if (result == favoriteModel) { return(Ok(result)); } else { return(BadRequest(result.ToString())); } }
public IHttpActionResult delete_contact(int id, int contactId) { UserModel user = db.UserModels.FirstOrDefault(u => u.UserId == id); ContactModel contact = user.ContactList.FirstOrDefault(c => c.ContactId == contactId); FavoriteModel favorite = user.FavoriteList.FirstOrDefault(f => f.Email.Equals(contact.Email)); user.FavoriteList.Remove(favorite); user.ContactList.Remove(contact); db.SaveChanges(); return(Ok(contact)); }
public IHttpActionResult update_favor(int id, int FavorId, FavoriteModel Favorite) { UserModel user = db.UserModels.FirstOrDefault(u => u.UserId == id); FavoriteModel other = user.FavoriteList.FirstOrDefault(f => f.FavorId == FavorId); if (other == null) { return(BadRequest("This Contact is not exist!")); } other.Name = Favorite.Name; other.Email = Favorite.Email; db.SaveChanges(); return(Ok(user)); }
/// <summary> /// 新增收藏 /// </summary> public bool CreateFavorite(FavoriteModel model) { int rows = 0; //判断重复收藏 if (DBHelper.GetScaler("SELECT COUNT(1) FROM dbo.Favorite WHERE ArticleID='" + model.ArticleID + "' AND CustomerID='" + model.CustomerID + "'") > 0) { return(false); } else { try { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into Favorite("); strSql.Append("FavoriteID,ArticleID,CustomerID,DataState,CreateDate)"); strSql.Append(" values ("); strSql.Append("@FavoriteID,@ArticleID,@CustomerID,@DataState,@CreateDate)"); SqlParameter[] parameters = { new SqlParameter("@FavoriteID", SqlDbType.UniqueIdentifier, 16), new SqlParameter("@ArticleID", SqlDbType.UniqueIdentifier, 16), new SqlParameter("@CustomerID", SqlDbType.UniqueIdentifier, 16), new SqlParameter("@DataState", SqlDbType.Int, 4), new SqlParameter("@CreateDate", SqlDbType.DateTime) }; parameters[0].Value = Guid.NewGuid(); parameters[1].Value = model.ArticleID; parameters[2].Value = model.CustomerID; parameters[3].Value = 0; parameters[4].Value = DateTime.Now; rows = DBHelper.ExecuteCommand(strSql.ToString(), parameters); } catch (Exception w6) { Tool.WritrErro(w6); } if (rows > 0) { return(true); } else { return(false); } } }
public ActionResult Index() { var currentId = (int)Session["userId"]; Product product = new Product(); FavoriteModel favorite = new FavoriteModel() { Name = product.Name, Image = product.Image, Price = product.Price, ProductId = product.Id, UserId = currentId }; favorite.MyFavoriteProducts = db.Favorite.Include(p => p.Product).Include(u => u.User).Where(u => u.UserId == currentId).ToList(); return(View(favorite)); }
public async Task <IActionResult> AddFavorite([FromBody] FavoriteModel favoriteModel) { try { var authorize = Barayand.Common.Services.TokenService.AuthorizeUser(Request); if (authorize < 1) { return(new JsonResult(ResponseModel.Error("Your login token has expired."))); } favoriteModel.F_UserId = authorize; return(new JsonResult(await _favoritrepostory.Insert(favoriteModel))); } catch (Exception ex) { return(null); } }
public FavoriteModel GetFavorite(string id) { FavoriteModel favoriteModel = new FavoriteModel(); favoriteModel.SongGetModels = new List <SongGetModel>(); var songCollection = new MongodbConnectionProvider().GeShantyDatabase().GetCollection <BsonDocument>("songs"); var songResults = songCollection.Find(new BsonDocument()).Limit(50).ToList(); foreach (BsonDocument result in songResults) { if (result != null) { SongGetModel res = BsonSerializer.Deserialize <SongGetModel>(result); favoriteModel.SongGetModels.Add(res); } } return(favoriteModel); }
public void Favorite_UpdatesRecipe() { var expected = new FavoriteModel { RecipeId = 20, UserId = "test" }; _mockUserRepo.Setup(s => s.GetByAuthId("test")).Returns(new User { Id = 1, AuthId = "test" }); var result = _controller.Favorite(expected) as OkResult; _mockRepo.Verify(s => s.FavoriteRecipe(expected.RecipeId, 1.ToString(), true), Times.Once); Assert.AreEqual(200, result?.StatusCode); }
private string AddFavorite(HttpContext context) { NameValueCollection nv = GetParas(context); bool result = false; string code = ""; string message = ""; if (context.User.Identity.IsAuthenticated && ((ShopIdentity)context.User.Identity) != null) { FavoriteBll fbll = new FavoriteBll(); FavoriteModel favModel = new FavoriteModel(); favModel.ContentId = int.Parse(nv["cid"]); favModel.UserId = ((ShopIdentity)context.User.Identity).UserId; favModel.ContentType = (ContentType)int.Parse(nv["ctype"]); switch (favModel.ContentType) { case ContentType.Product: NoName.NetShop.Product.BLL.ProductModelBll pbll = new NoName.NetShop.Product.BLL.ProductModelBll(); NoName.NetShop.Product.Model.ProductModel pmodel = pbll.GetModel(favModel.ContentId); favModel.FavoriteName = pmodel.ProductName; favModel.FavoriteUrl = pmodel.ProductUrl; break; case ContentType.Solution: NoName.NetShop.Solution.BLL.SuiteBll sbll = new NoName.NetShop.Solution.BLL.SuiteBll(); NoName.NetShop.Solution.Model.SuiteModel smodel = sbll.GetModel(favModel.ContentId); favModel.FavoriteName = smodel.SuiteName; favModel.FavoriteUrl = ConfigurationManager.AppSettings["siteurl"] + "/solution/suitedetail.aspx?suite=" + smodel.SuiteId; break; } fbll.Add(favModel); result = true; message = "收藏成功"; } else { result = false; message = "您还没有登录,请先登录!"; } return(GetJsonResult(result, code, message)); }
public IActionResult Add(string id) { string userId = User.Identity.Name; // does film exist var films = _mongoDB.GetCollection <BsonDocument>("films"); ObjectId filmId; if (!ObjectId.TryParse(id, out filmId)) { return(NotFound()); } var filmBson = films.Find($"{{ _id: ObjectId('{filmId}') }}").FirstOrDefault(); if (filmBson == null) { return(NotFound()); } var film = BsonSerializer.Deserialize <Film>(filmBson); //is already in favorites var favorites = _mongoDB.GetCollection <BsonDocument>("favorites"); var exist = favorites.Find($"{{FilmId: ObjectId('{filmId}'), UserId: ObjectId('{userId}')}}").FirstOrDefault(); if (exist != null) { return(Redirect("/film/detail/?id=" + id)); } FavoriteModel toAdd = new FavoriteModel() { FilmId = filmId, UserId = ObjectId.Parse(userId), Time = DateTime.Now }; favorites.InsertOne(toAdd.ToBsonDocument()); return(Redirect("/film/detail/?id=" + id)); }