public HttpResponseMessage AddNewReview(REVIEW review) { try { var commonService = new CommonService(); var id = commonService.AddNewReview(review); var response = Request.CreateResponse(HttpStatusCode.OK, id); return response; } catch (Exception e) { var error = Request.CreateResponse(HttpStatusCode.InternalServerError, e.Message); return error; } }
// TODO : TO REVISIT User should be able to add 1 review (rating and comment) for a product/ service /// <summary> /// Add a new review for a product/ service by a user /// </summary> /// <param name="userReview"></param> /// <returns></returns> public Guid AddNewReview(REVIEW userReview) { try { if (userReview == null) throw new ArgumentNullException("UserReview", "UserReview can not be null"); if((!userReview.PRODUCTID.HasValue || userReview.PRODUCTID.Value == Guid.Empty) && (!userReview.SERVICEID.HasValue || userReview.SERVICEID.Value == Guid.Empty)) throw new ArgumentException("Both PRODUCTID SERVICEID can not be null together", "UserReview"); if ((userReview.PRODUCTID.HasValue && userReview.PRODUCTID.Value != Guid.Empty) && (userReview.SERVICEID.HasValue && userReview.SERVICEID.Value != Guid.Empty)) throw new ArgumentException("Both PRODUCTID SERVICEID can not have values together", "UserReview"); if(!userReview.REVIEWERID.HasValue || userReview.REVIEWERID.Value == Guid.Empty) throw new ArgumentException("REVIEWERID can not be null", "UserReview"); if (userReview.RATING == null && string.IsNullOrEmpty(userReview.COMMENTS)) return Guid.Empty; if (!userReview.ID.HasValue || userReview.ID.Value == Guid.Empty) userReview.ID = Guid.NewGuid(); userReview.REVIEWDATE = DateTime.Now; using (APIShopKaro.Models.apsteamCFHEntities db = new APIShopKaro.Models.apsteamCFHEntities()) { try { db.REVIEWS.Add(userReview); db.SaveChanges(); } catch (System.Data.DataException e) { throw new Exception(e.InnerException.InnerException.Message); } } return userReview.ID.Value; } catch(Exception e) { throw; } }