/// <summary> /// Cập nhật điểm người dùng /// </summary> /// <param name="user"></param> /// <param name="document"></param> /// <returns></returns> public async Task <bool> UpdatePointAfterDownload(PosterParam posterParam) { var reducePoint = new User(); var increasePoint = new User(); var document = new Document(); bool res; var posterID = new MySqlParameter("@posterID", posterParam.Poster); var downloaderID = new MySqlParameter("@downloaderID", posterParam.Downloader); increasePoint = await _context.Users.FromSqlRaw("Select * from Users where UserID=@posterID", posterID).FirstOrDefaultAsync(); reducePoint = await _context.Users.FromSqlRaw("Select * from Users where UserID=@downloaderID", downloaderID).FirstOrDefaultAsync(); document = await _context.Document.SingleOrDefaultAsync(x => x.DocumentID == posterParam.DocumentID); if (increasePoint != null && reducePoint != null && document != null) { increasePoint.Point = increasePoint.Point + (posterParam.Point / 2); reducePoint.Point = reducePoint.Point - posterParam.Point; document.DownloadCount++; _context.Entry(reducePoint).State = EntityState.Modified; _context.Entry(document).State = EntityState.Modified; _context.Entry(increasePoint).State = EntityState.Modified; _context.SaveChanges(); res = true; } else { res = false; } return(res); }
public async Task <ServiceResponse> UpdatePointAfterDownload(PosterParam posterParam) { ServiceResponse result = new ServiceResponse(); try { result.Data = await _userBL.UpdatePointAfterDownload(posterParam); result.Code = ServiceResponseCode.Success; result.Success = true; } catch (Exception ex) { result.OnExeption(ex); } return(result); }