public void CreateOrderRating(OrderRating orderRatingToCreate, Order order) { if (orderRatingToCreate == null) { throw new ArgumentNullException("orderRatingToCreate"); } using (var dbContextScope = _dbContextScopeFactory.Create()) { var foundOrderRating = _orderRatingRepository.FindByOrderId(orderRatingToCreate.Order.Id); if (foundOrderRating != null) { //TODO: OrderRatingAlreadyExistsException throw new Exception(); } //NO HACK var context = dbContextScope.DbContexts.Get <EShopDbContext>(); context.Orders.Attach(order); orderRatingToCreate.Order = order; _orderRatingRepository.Add(orderRatingToCreate); dbContextScope.SaveChanges(); } }
public ActionResult SetRating(FormCollection form) { var comment = form["Comment"].ToString(); var orderId = int.Parse(form["OrderId"]); var rating = int.Parse(form["rating"]); _logger.InfoFormat("Add rating for oder with id [{0}]. Comment : [{1}], rating : [{2}]", orderId, comment, rating); if (rating == 0) { return(Json(new { Success = "false", ErrorMsg = "Please set a rating" })); } if (comment.Equals("")) { return(Json(new { Success = "false", ErrorMsg = "Please enter a comment" })); } int? currentCustomerId = (int)Session["AccountId"]; Customer currentCustomer = _customerAccountService.GetCustomer((int)currentCustomerId); Order order = currentCustomer.Orders.SingleOrDefault(o => o.Id == orderId); OrderRating orderRating = new OrderRating { Rating = rating, Comment = comment, Order = order }; _orderRatingService.CreateOrderRating(orderRating, order); _logger.InfoFormat("Rating for order with id [{0}] was successfully added", orderId); return(PartialView("_OrderRatingTable", orderRating)); }
public OrderRating GetOrderRatingByOrderId(int orderId) { using (var dbContextScope = _dbContextScopeFactory.CreateReadOnly()) { OrderRating orderRating = _orderRatingRepository.FindByOrderId(orderId); if (orderRating == null) { throw new ArgumentException(String.Format("Invalid value provided for orderId: [{0}].", orderId)); } return(orderRating); } }
public ActionResult GetRating(FormCollection fc) { int orderID = 0; try { orderID = Convert.ToInt32(fc["OrderId"]); } catch (FormatException) { return(Content("<html></html>")); } _logger.InfoFormat("Get rating for order with id [{0}]", orderID); OrderRating orderRating = _orderRatingService.GetOrderRatingByOrderId(orderID); _logger.InfoFormat("Get rating for order with id [{0}] was successful", orderID); return(PartialView("_OrderRatingTable", orderRating)); }
public void Remove(OrderRating orderRating) { DbContext.OrderRatings.Remove(orderRating); }
public void Add(OrderRating orderRating) { DbContext.OrderRatings.Add(orderRating); //DbContext.ObjectStateManager.ChangeObjectState(); }