public ActionResult Add()
        {
            var model = new AddRestaurantVm();

            model.Districts  = service.Uow.Districts.GetAll();
            model.Features   = service.Uow.Features.GetActives();
            model.Categories = service.Uow.Categories.GetAll();
            return(View(model));
        }
        public ActionResult Add(AddRestaurantVm data)
        {
            if (ModelState.IsValid)
            {
                var restaurant = new Restaurant();
                restaurant.RestaurantKey = Guid.NewGuid().ToString();
                restaurant.Name          = data.RestaurantName;
                restaurant.Adress        = data.Adress;
                restaurant.PhoneNumber   = data.PhoneNumber;
                restaurant.DistrictId    = data.DistrictId;
                restaurant.AddedBy       = User.Identity.GetUserId();

                service.Uow.Restaurants.Insert(restaurant);
                service.Uow.Save();

                int restaurantId = service.Uow.Restaurants.GetByRestaurantKey(restaurant.RestaurantKey).Id;

                WebImage img = new WebImage(data.RestaurantImage.InputStream);
                img.Resize(640, 360, false);
                string fileName = restaurantId + "_" + DateTime.Now.ToString("yyyyMMddHHmmssfffffff");
                img.FileName = fileName + "." + img.ImageFormat;
                restaurant.CoverImagePath = "/Content/Images/CoverPics/" + img.FileName;
                img.Save(Server.MapPath("/Content/Images/CoverPics/") + img.FileName);

                service.Uow.Restaurants.Update(restaurant);
                service.Uow.Save();

                if (data.FeatureIds != null)
                {
                    foreach (var featureId in data.FeatureIds)
                    {
                        var restaurantFeature = new RestaurantFeature()
                        {
                            RestaurantId = restaurantId,
                            FeatureId    = featureId
                        };
                        service.Uow.RestaurantFeatures.Insert(restaurantFeature);
                    }
                }
                if (data.CategoryIds != null)
                {
                    foreach (var categoryId in data.CategoryIds)
                    {
                        var restaurantCategory = new RestaurantCategory()
                        {
                            RestaurantId = restaurantId,
                            CategoryId   = categoryId
                        };
                        service.Uow.RestaurantCategories.Insert(restaurantCategory);
                    }
                }
                var dummyReview = new Review()
                {
                    Content         = "Dummy Content",
                    Score           = null,
                    UserId          = User.Identity.GetUserId(),
                    RestaurantId    = restaurantId,
                    isConfirmed     = true,
                    AddedDate       = DateTime.Now,
                    LastUpdatedDate = DateTime.Now,
                    IsActive        = true
                };
                service.Uow.Reviews.Insert(dummyReview);
                service.Uow.Save();
            }
            return(RedirectToAction("Add"));
        }