Esempio n. 1
0
        public void Create(DishReviewEditModel model)
        {
            int dishId  = model.DishId ?? 0;
            int placeId = placeService.GetPlaceId(model.Place);

            placeTypeService.CreatePlaceTypesForPlace(placeId, model.Place.GTypes);

            if (!model.DishId.HasValue)
            {
                var newDish = new Dish
                {
                    CreatedByUserId = UserHelper.GetCurrentUserId(),
                    CreatedDateTime = DateTime.Now,
                    Name            = model.DishName,
                    IsConfirmed     = false,
                    IsValid         = true
                };

                dishRepository.Insert(newDish);

                dishId = newDish.Id;
            }

            int?imageId = null;

            if (!string.IsNullOrEmpty(model.ImageUri))
            {
                imageId = imageService.CreateImage(model.ImageUri);
            }

            var review = new Review
            {
                CreatedByUserId = UserHelper.GetCurrentUserId(),
                CreatedDateTime = DateTime.Now,
                Text            = model.Review,
                PlaceId         = placeId,
                IsValid         = true,
                Rating          = model.Rating,
                ImageId         = imageId
            };

            reviewRepository.Insert(review);

            var dishReview = new DishReview
            {
                DishId   = dishId,
                ReviewId = review.Id
            };

            dishService.CreateDishTags(model.TagIdList, dishId);

            dishReviewRepository.Insert(dishReview);
        }