public void Put(Guid id, TradeReviewInfo value) { AccountInfo account = new AccountController().Get(); using (DatabaseContext context = new DatabaseContext()) { TradeReview review = (from t in context.TradeReviews where t.Guid == id select t).First(); if (review.BuyerGuid != account.Guid && review.SellerGuid != account.Guid) { throw new HttpResponseException(HttpStatusCode.Forbidden); } //this feedback is from the BUYER if (review.BuyerGuid == account.Guid) { review.BuyerRating = value.Rating; review.BuyerComment = value.Comment; } else if (review.SellerGuid == account.Guid) { review.SellerRating = value.Rating; review.SellerComment = value.Comment; } review.LastModified = DateTime.UtcNow; context.SaveChanges(); } }
static FeedbackInfo ConvertFeedbackGiven(TradeReview review, Guid reviewerGuid) { using (DatabaseContext context = new DatabaseContext()) { var revieweeGuid = review.BuyerGuid == reviewerGuid ? review.SellerGuid : review.BuyerGuid; var reviewerComment = review.BuyerGuid == reviewerGuid ? review.BuyerComment : review.SellerComment; var reviewerRating = review.BuyerGuid == reviewerGuid ? review.BuyerRating : review.SellerRating; var reviewer = (from a in context.Accounts where a.Guid == reviewerGuid select a).First(); var reviewee = (from a in context.Accounts where a.Guid == revieweeGuid select a).First(); return(new FeedbackInfo { ReviewerGuid = reviewerGuid, ReviewerName = reviewer.Username, RevieweeGuid = revieweeGuid, RevieweeName = reviewee.Username, Comment = reviewerComment, Rating = reviewerRating, Created = review.Created }); } }
public void Test_Create() { TradeReviewBLL bll = new TradeReviewBLL(_unit); TradeReview tr = bll.GetByID(5); bll.PopulateReview(tr); bll.Update(tr); //bll.CreateTradeReview(new Entity.TradeReview //{ // TradePositionId = 2008, // Notes = "test notes", // UpdatedBy = "System", // UpdatedDT = DateTime.Now //}); }
public async Task <IHttpActionResult> GetTradeReviewByPosition(int positionId) { TradeReview review = null; try { review = new TradeReviewBLL(_unit).GetTradeReviewByPositionId(positionId); } catch (ApplicationException appEx) { return(BadRequest(appEx.Message)); } catch (Exception ex) { LogHelper.Error(_log, ex.ToString()); return(InternalServerError(ex)); } return(Ok(review)); }
public async Task <IHttpActionResult> UpdateTradeReview(TradeReview review) { try { var currentUser = await GetCurrentUser(); review.UpdatedBy = currentUser.Id; review.UpdatedDT = DateTime.Now; new TradeReviewBLL(_unit).Update(review); } catch (ApplicationException appEx) { return(BadRequest(appEx.Message)); } catch (Exception ex) { LogHelper.Error(_log, ex.ToString()); return(InternalServerError(ex)); } return(Ok(review)); }