public ActionResult Update(int id)
        {
            var model = new UpdateRestaurantVm();

            model.RestaurantId = id;
            model.Districts    = service.Uow.Districts.GetAll();
            model.Features     = service.Uow.Features.GetActives();
            model.Categories   = service.Uow.Categories.GetAll();
            var restaurant = service.Uow.Restaurants.GetById(id);

            model.RestaurantName = restaurant.Name;
            model.Adress         = restaurant.Adress;
            model.PhoneNumber    = restaurant.PhoneNumber;
            var categories = service.Uow.RestaurantCategories.GetByRestaurantIdIncludeCategories(id);

            model.CategoryIds = new List <int>();
            foreach (var category in categories)
            {
                model.CategoryIds.Add(category.CategoryId);
            }
            model.DistrictId = restaurant.DistrictId;
            var features = service.Uow.RestaurantFeatures.GetByRestaurantIdIncludeFeatures(id);

            model.FeatureIds = new List <int>();
            foreach (var feature in features)
            {
                model.FeatureIds.Add(feature.FeatureId);
            }
            model.CoverImagePath = restaurant.CoverImagePath;
            return(View(model));
        }
        public ActionResult Update(UpdateRestaurantVm data)
        {
            var restaurant = service.Uow.Restaurants.GetById(data.RestaurantId);

            restaurant.Name            = data.RestaurantName;
            restaurant.Adress          = data.Adress;
            restaurant.PhoneNumber     = data.PhoneNumber;
            restaurant.DistrictId      = data.DistrictId;
            restaurant.LastUpdatedDate = DateTime.Now;

            if (data.RestaurantImage != null)
            {
                if (System.IO.File.Exists(Server.MapPath(restaurant.CoverImagePath)))
                {
                    System.IO.File.Delete(Server.MapPath(restaurant.CoverImagePath));
                }

                WebImage img = new WebImage(data.RestaurantImage.InputStream);
                img.Resize(640, 360, false);
                string fileName = restaurant.Id + "_" + 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);

            if (data.FeatureIds != null)
            {
                service.Uow.RestaurantFeatures.DeleteByRestaurantId(data.RestaurantId);
                foreach (var featureId in data.FeatureIds)
                {
                    var restaurantFeature = new RestaurantFeature()
                    {
                        RestaurantId = data.RestaurantId,
                        FeatureId    = featureId
                    };
                    service.Uow.RestaurantFeatures.Insert(restaurantFeature);
                }
            }

            if (data.CategoryIds != null)
            {
                service.Uow.RestaurantCategories.DeleteByRestaurantId(data.RestaurantId);
                foreach (var categoryId in data.CategoryIds)
                {
                    var restaurantCategory = new RestaurantCategory()
                    {
                        RestaurantId = data.RestaurantId,
                        CategoryId   = categoryId
                    };
                    service.Uow.RestaurantCategories.Insert(restaurantCategory);
                }
            }
            service.Uow.Save();
            return(RedirectToAction("List"));
        }