/// <summary> /// 点赞 /// </summary> /// <param name="praise"></param> /// <param name="postId"></param> public void AddPraise(Praise praise, string postId) { FilterDefinition <Posts> filter = Filter.Where(m => m.ObjId == postId); var update = UpdateBuilder.Push("Praises", praise); Collection.UpdateOne(filter, update); }
public static Praise GetPraise(UserPraises user, uint id) { var result = from p in user.Praises where p.ID == id select p; Praise praise = result.FirstOrDefault(); return(praise); }
public static Praise CreatePraise(SocketUser user, uint id, string reason) { Praise praise = new Praise { ID = id, GiverID = user.Id, Reason = reason, GivenAt = DateTime.Now }; return(praise); }
public OutPutData AddPraise([FromBody] AddPraiseParam param) { if (postsService.CurrentRepository.Exist(e => e.ObjId == param.PostId && e.Praises.Any(p => p.UserName == Loginer.UserName))) { return(Fail("已点赞")); } Praise praise = new Praise { CreateTime = DateTime.Now, UserName = Loginer.UserName, Id = Guid.NewGuid().ToString() }; postsService.CurrentRepository.AddPraise(praise, param.PostId); return(Success()); }
/// <summary> /// 赞 专门赞状态的 /// </summary> /// <param name="userid"></param> /// <param name="stateid">状态id</param> /// <param name="statetype">判断是状态 1还是图片 2 </param> /// <returns>0 说明已经赞过了 1是成功的</returns> public JsonResult MakeaParise(int userid, int stateid, int statetype) { // 重复判断 var stype = (StateType)statetype; var id = CheckValid(); var pr = LoveDb.One((Praise p) => p.UserId == id && p.ToUserId == userid && p.StateType == stype && p.StateId == stateid); if (pr != null) { return(Json(0));//说明已经赞过了 } // 增加一个赞 var praise = new Praise { ActionTime = DateTime.Now, StateId = stateid, StateType = stype, ToUserId = userid, UserId = id }; LoveDb.Add(praise); // 转化为消息 LoveDb.Add(new Message { ActionTime = praise.ActionTime, Content = statetype == 1 || statetype == 0 ? "赞了你发布的状态:" : "赞了你的图片", FromUserId = id,//当时人发的 ToUserId = userid, FromUserName = GetUserNameById(id), IsReaded = false, MegType = MegType.Praise,//是赞的一中. StateType = stype, StateId = stateid }); //这条状态或者图片的赞也要加一 LoveDb.StateOrImagePraiseCountAdd(stateid, stype); // 用户热度加1 LoveDb.PraiseCountAdd(userid); // 用户热度加1 return(Json(1)); }
public async Task Praise(SocketUser user, [Remainder] string reason) { GuildCfg guildCfg = GuildsCfgs.GetGuildCfg(Context.Guild); ISocketMessageChannel generalChannel = (ISocketMessageChannel)Methods.GetTextChannelByID(Context.Guild, guildCfg.GeneralChannelID); UserPraises account = UsersPraises.GetUserPraises(user.Id); uint id = (uint)account.Praises.Count; Praise praise = Praises.CreatePraise(user, id, reason); account.Praises.Add(praise); UsersPraises.Save(); await generalChannel.SendMessageAsync($"Użytkownik {user.Mention} otrzymał pochwałę od {Context.User.Username}. Powód: {reason}"); await Context.Channel.SendMessageAsync("Dodano pochwałę."); }
void SavePraise(Praise praise) { //recover validator var validator = EntityValidatorFactory.CreateValidator(); if (validator.IsValid(praise)) //if favorite is valid { //add the favorite into the repository _praiseRepository.Add(praise); //commit the unit of work _praiseRepository.UnitOfWork.Commit(); } else //customer is not valid, throw validation errors { throw new ApplicationValidationErrorsException(validator.GetInvalidMessages <Praise>(praise)); } }
/// <summary> /// delete a user info /// </summary> /// <param name="Id"></param> public void RemovePraiseDTO(Guid id) { if (id == Guid.Empty) { LoggerFactory.CreateLog().LogWarning(Messages.warning_CannotRemoveNonExistingPraise); } else { var praise = _praiseRepository.Get(id); var deletePraise = new Praise(); deletePraise.ChangeCurrentIdentity(id); //disable account "delete" _praiseRepository.Remove(deletePraise); //commit changes _praiseRepository.UnitOfWork.Commit(); } }
static void Main(string[] args) { Mail mail = new Mail("wow, super product, good job!"); // ceo Mail mail2 = new Mail("wanna complain, this product is bad"); // law Mail mail3 = new Mail("wanna order product no 222"); // orders Mail mail4 = new Mail("asd"); // pr MailHandler handler = new Praise(); MailHandler complaint = new Complaint(); MailHandler order = new Order(); MailHandler rest = new Unimportant(); // Handler (praise) -> complaint -> order -> unimportant handler.setNext(complaint); complaint.setNext(order); order.setNext(rest); handler.ProcessRequest(mail); handler.ProcessRequest(mail2); handler.ProcessRequest(mail3); handler.ProcessRequest(mail4); }
public async Task Command(IGuildUser user = null, [Remainder] string reason = null) { Server server = await DatabaseQueries.GetOrCreateServerAsync(Context.Guild.Id); List <Praise> userPraise = await DatabaseQueries.GetAllForServerAndUserAsync <Praise>(Context.User.Id, server.ServerId); double lastGivenPraise = DatabaseQueries.GetLastPraiseTime(Context.User.Id, Context.Guild.Id); if (user == null && reason == null) { await SendBasicSuccessEmbedAsync($"You currently have `{userPraise.Count}` praise."); return; } if (user == null) { var curEmbed = new KaguyaEmbedBuilder { Description = $"You currently have `{userPraise.Count}` praise." }; await Context.Channel.SendEmbedAsync(curEmbed); return; } if (user == Context.User) { var userErrorEmbed = new KaguyaEmbedBuilder { Description = $"You can't praise yourself!" }; userErrorEmbed.SetColor(EmbedColor.RED); await ReplyAsync(embed : userErrorEmbed.Build()); return; } double cooldownTime = DateTime.Now.AddHours(-server.PraiseCooldown).ToOADate(); if (!(lastGivenPraise < cooldownTime)) { var timeErrorEmbed = new KaguyaEmbedBuilder { Description = $"Sorry, you must wait " + $"`{(DateTime.FromOADate(lastGivenPraise) - DateTime.FromOADate(cooldownTime)).Humanize()}` " + $"before giving praise again." }; timeErrorEmbed.SetColor(EmbedColor.RED); await ReplyAsync(embed : timeErrorEmbed.Build()); return; } if (reason == null) { reason = "No reason provided."; } var praise = new Praise { UserId = user.Id, ServerId = server.ServerId, GivenBy = Context.User.Id, Reason = reason, Server = server, TimeGiven = DateTime.Now.ToOADate() }; await DatabaseQueries.InsertAsync(praise); List <Praise> newTargetPraise = await DatabaseQueries.GetAllForServerAndUserAsync <Praise>(praise.UserId, praise.ServerId); int newTargetPraiseCount = newTargetPraise.Count; var embed = new KaguyaEmbedBuilder { Description = $"Successfully awarded `{user}` with `+1` praise.\n" + $"Reason: `{reason}`", Footer = new EmbedFooterBuilder { Text = $"{user.Username} now has {newTargetPraiseCount} praise. " + $"You have {userPraise.Count} praise." } }; await ReplyAsync(embed : embed.Build()); }
/// <summary> /// 点赞 /// </summary> /// <param name="praise"></param> /// <param name="postId"></param> public void AddPraise(Praise praise, string postId) { }