public ActionResult ServicePage(ServicePageViewModel model, long id) { try { var service = _servicesManager.GetById(id); model = Mapper.Map <Services, ServicePageViewModel>(service); model.IdUserInSystem = Convert.ToInt64(Session["UserId"]); List <PhotoViewModel> photos = new List <PhotoViewModel>(); IQueryable <ServicePhoto> photosList; photosList = _servicePhotoManager.GetServicePhotosByServiceId(service.id).OrderByDescending(x => x.photo.date); foreach (var photo in photosList) { photos.Add(Mapper.Map <ServicePhoto, PhotoViewModel>(photo)); } model.Photos = photos; var commentsService = _commentManager.GetCommentsByServiceId(service.id).OrderByDescending(x => x.dateOfComment); List <CommentViewModel> comments = new List <CommentViewModel>(); foreach (var comment in commentsService) { comments.Add(Mapper.Map <Comments, CommentViewModel>(comment)); } model.Comments = comments; return(View(model)); } catch (Exception) { return(View(model)); } }
public ActionResult NewOrder(ServicePageViewModel model) { try { var service = _servicesManager.GetById(model.Id); model.Price = service.price; var entity = Mapper.Map <ServicePageViewModel, Order>(model); _orderManager.Add(entity); return(RedirectToRoute("UserPage")); } catch (Exception) { return(RedirectToRoute("ServicePage", new { id = model.Id })); } }