//------------------------------------------------------------------------------------------------- public Result VoteToIdea(IdeaPointDto vote) { if (vote.POINT < 0) { vote.POINT = -1; } else if (vote.POINT > 0) { vote.POINT = 1; } else { vote.POINT = 0; } if (_Repository.IsIdeaLocked(vote.IDEA_ID)) { return(new Result() { value = false, content = "ایده توسط کمیته بررسی شده و یا وجود ندارد و قابل رای دهی نیست" }); } else { return(_Repository.VoteToIdea(vote)); } }
//---------------------------------------------------------------------------------------------------------- public Result VoteToIdea(IdeaPointDto voteDetail) { Result result = new Result(); using (_db = new IdeaManagmentDatabaseEntities()) { var idea_point = _db.IDEA_POINTS.FirstOrDefault(x => x.IDEA_ID == voteDetail.IdeaId && x.USERNAME == voteDetail.Username); if (idea_point == null) { var idea = _db.IDEAS.FirstOrDefault(x => x.ID == voteDetail.IdeaId); if (idea == null) { result.Value = false; result.Content = "ایده پیدا نشد"; return(result); } var user = _db.USERS.FirstOrDefault(x => x.USERNAME == voteDetail.Username); if (user == null) { result.Value = false; result.Content = "کاربر پیدا نشد"; return(result); } ; if (idea.USERNAME == voteDetail.Username) { result.Value = false; result.Content = "به ایده ی خود نمی شود رای داد"; return(result); } IDEA_POINTS idea_point_ = new IDEA_POINTS() { IDEA_ID = voteDetail.IdeaId, USERNAME = voteDetail.Username, SAVE_DATE = DateTime.Now, POINT = voteDetail.Point }; _db.IDEA_POINTS.Add(idea_point_); _db.SaveChanges(); result.Value = true; result.Content = "به ایده امتیاز داده شد"; return(result); } idea_point.POINT = voteDetail.Point; idea_point.MODIFY_DATE = DateTime.Now; _db.SaveChanges(); result.Value = true; result.Content = "امتیاز ایده اصلاح شد"; return(result); } }
public HttpResponseMessage VoteToIdea(IdeaPointDto voteDetail) { var res = _business.VoteToIdea(voteDetail); if (res.Value == true) { return(Request.CreateResponse(HttpStatusCode.OK, res.Content)); } else { return(Request.CreateResponse(HttpStatusCode.PreconditionFailed, res.Content)); } }