public ActionResult EditBusiness([Bind(Exclude = "Logo")] BusinessFormViewModel viewModel)
        {
            if (!ModelState.IsValid)
            {
                viewModel.Categories = unitOfWork.Categories.GetCategories();
                viewModel.Locations  = unitOfWork.Locations.GetLocations();
                viewModel.Areas      = unitOfWork.Areas.GetAreas();
                return(View("RegisterBusiness", viewModel));
            }

            // find corresponding gig
            var userId     = User.Identity.GetUserId();
            var restaurant = unitOfWork.Businesses.GetRestaurant(viewModel.Id, userId);

            CheckUpdateCategoryLocationArea(viewModel);


            viewModel.Areas      = unitOfWork.Areas.GetAreas();
            viewModel.Locations  = unitOfWork.Locations.GetLocations();
            viewModel.Categories = unitOfWork.Categories.GetCategories();

            restaurant.UpdateRestaurant(viewModel);
            unitOfWork.Complete();
            return(RedirectToAction("MyBusinesses", "Restaurant"));
        }
        public static Restaurant RegisterARestaurantWithOwnership(BusinessFormViewModel businessFormViewModel, byte[] imageData)
        {
            var restaurant = new Restaurant(businessFormViewModel);

            restaurant.Logo = imageData;
            return(restaurant);
        }
예제 #3
0
        public IActionResult EditBusinessForm(BusinessFormViewModel vm)
        {
            var model = Mapper.Map <BusinessFormViewModel, BusinessFormData>(vm);

            model = businessFormsRepo.Update(model);
            ViewData["Message"] = string.Format("Successfully Updated: {0}", model.FormName);
            return(View("Result"));
        }
        public ActionResult Edit(int id)
        {
            var userId     = User.Identity.GetUserId();
            var restaurant = unitOfWork.Businesses.GetRestaurant(id, userId);

            var viewModel = BusinessFormViewModel.CreateBusinessFormViewModel(restaurant, unitOfWork.Categories.GetCategories(),
                                                                              unitOfWork.Locations.GetLocations(), unitOfWork.Areas.GetAreas());


            return(View("RegisterBusiness", viewModel));
        }
        public ActionResult RegisterBusiness()
        {
            var viewModel = new BusinessFormViewModel
            {
                Categories = unitOfWork.Categories.GetCategories(),
                Locations  = unitOfWork.Locations.GetLocations(),
                Areas      = unitOfWork.Areas.GetAreas(),
                Heading    = "Register a business"
            };

            return(View("RegisterBusiness", viewModel));
        }
        public ActionResult RegisterBusiness([Bind(Exclude = "Logo")] BusinessFormViewModel businessFormViewModel)
        {
            if (!ModelState.IsValid)
            {
                businessFormViewModel.Categories = unitOfWork.Categories.GetCategories();
                businessFormViewModel.Locations  = unitOfWork.Locations.GetLocations();
                businessFormViewModel.Areas      = unitOfWork.Areas.GetAreas();
                businessFormViewModel.Heading    = "Register business";
                return(View("RegisterBusiness", businessFormViewModel));
            }


            byte[] imageData = null;
            if (Request.Files.Count > 0)
            {
                HttpPostedFileBase poImgFile = Request.Files["Logo"];

                using (var binary = new BinaryReader(poImgFile.InputStream))
                {
                    imageData = binary.ReadBytes(poImgFile.ContentLength);
                }
            }

            string userId = User.Identity.GetUserId();


            CheckUpdateCategoryLocationArea(businessFormViewModel);
            businessFormViewModel.Areas      = unitOfWork.Areas.GetAreas();
            businessFormViewModel.Locations  = unitOfWork.Locations.GetLocations();
            businessFormViewModel.Categories = unitOfWork.Categories.GetCategories();

            var restaurant = Restaurant.RegisterARestaurantWithOwnership(businessFormViewModel, imageData);



            unitOfWork.Businesses.AddRestaurant(restaurant);

            unitOfWork.Complete();

            unitOfWork.RestaurantOwnerships.AddRestaurantOwnership(RestaurantOwnership.CeateRestaurantOwnership(restaurant, userId));

            unitOfWork.EventPlaces.AddEventPlace(EventPlace.CreateEventPlace(restaurant));

            unitOfWork.Complete();

            return(RedirectToAction("MyBusinesses", "Restaurant"));
        }
 public void UpdateRestaurant(BusinessFormViewModel viewModel)
 {
     this.Vat          = viewModel.VatNumber;
     this.Name         = viewModel.Name;
     this.Capacity     = viewModel.Capacity;
     this.CategoryID   = viewModel.Categories.SingleOrDefault(c => c.Name == viewModel.Category).Id;
     this.AreaID       = viewModel.Areas.SingleOrDefault(a => a.Name == viewModel.Area).Id;
     this.LocationID   = viewModel.Locations.SingleOrDefault(l => l.Name == viewModel.Location).ID;
     this.StreetName   = viewModel.StreetName;
     this.StreetNumber = viewModel.StreetNumber;
     this.Lattitude    = viewModel.Lattitude;
     this.Longitude    = viewModel.Longitude;
     this.PostalCode   = viewModel.PostalCode;
     this.PhoneNumber  = viewModel.PhoneNumber;
     this.Category     = viewModel.Categories.SingleOrDefault(c => c.Name == viewModel.Category);
     this.Area         = viewModel.Areas.SingleOrDefault(a => a.Name == viewModel.Area);
     this.Location     = viewModel.Locations.SingleOrDefault(l => l.Name == viewModel.Location);
 }
 private Restaurant(BusinessFormViewModel businessFormViewModel)
 {
     Name         = businessFormViewModel.Name;
     Capacity     = businessFormViewModel.Capacity;
     CategoryID   = businessFormViewModel.Categories.SingleOrDefault(c => c.Name == businessFormViewModel.Category).Id;
     AreaID       = businessFormViewModel.Areas.SingleOrDefault(a => a.Name == businessFormViewModel.Area).Id;
     LocationID   = businessFormViewModel.Locations.SingleOrDefault(l => l.Name == businessFormViewModel.Location).ID;
     StreetName   = businessFormViewModel.StreetName;
     StreetNumber = businessFormViewModel.StreetNumber;
     Lattitude    = businessFormViewModel.Lattitude;
     Longitude    = businessFormViewModel.Longitude;
     PostalCode   = businessFormViewModel.PostalCode;
     Vat          = businessFormViewModel.VatNumber;
     PhoneNumber  = businessFormViewModel.PhoneNumber;
     Category     = businessFormViewModel.Categories.SingleOrDefault(c => c.Name == businessFormViewModel.Category);
     Area         = businessFormViewModel.Areas.SingleOrDefault(a => a.Name == businessFormViewModel.Area);
     Location     = businessFormViewModel.Locations.SingleOrDefault(l => l.Name == businessFormViewModel.Location);
 }
예제 #9
0
        public async Task <IActionResult> Edit(int id, BusinessFormViewModel businessModel)
        {
            if (!ModelState.IsValid)
            {
                return(View(businessModel));
            }

            var userId = this.userManager.GetUserId(User);

            if (businessModel.Image.HasValidImage())
            {
                await this.businesses.SetImage(id, businessModel.Image.
                                               SaveImage(id, businessModel.Type.ToString(), businessModel.Name, BusinessImagesPath));
            }

            var update = await this.businesses.EditAsync(
                id,
                businessModel.Name,
                businessModel.Type,
                businessModel.WebPageUrl,
                businessModel.Address,
                businessModel.LatLocation,
                businessModel.LngLocation,
                businessModel.PetTypes,
                businessModel.City,
                businessModel.PicUrl,
                businessModel.IsApproved,
                businessModel.Note,
                userId);

            if (!update)
            {
                return(this.BadRequest());
            }

            this.TempData.AddWarningMessage(string.Format(SuccessfullEdit, businessModel.Name));


            return(RedirectToAction(nameof(Index)));
        }
        private void CheckUpdateCategoryLocationArea(BusinessFormViewModel viewModel)
        {
            var category = unitOfWork.Categories.GetCategory(viewModel.Category);

            if (category == null)
            {
                category = new Category()
                {
                    Name = viewModel.Category
                };
                unitOfWork.Categories.AddCategory(category);
                unitOfWork.Complete();
            }

            var location = unitOfWork.Locations.GetLocation(viewModel.Location);

            if (location == null)
            {
                location = new Location()
                {
                    Name = viewModel.Location
                };
                unitOfWork.Locations.AddLocation(location);
                unitOfWork.Complete();
            }


            var area = unitOfWork.Areas.GetArea(viewModel.Area);

            if (area == null)
            {
                area = new Area()
                {
                    Name = viewModel.Area
                };
                unitOfWork.Areas.AddArea(area);
                unitOfWork.Complete();
            }
        }
예제 #11
0
        public async Task <IActionResult> Create(BusinessFormViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            var userId = this.userManager.GetUserId(User);

            var isApproved = false;

            var businessId = await this.businesses.CreateAsync(
                model.Name,
                model.Type,
                model.WebPageUrl,
                model.Address,
                model.LatLocation,
                model.LngLocation,
                model.PetTypes,
                model.City,
                model.PicUrl,
                isApproved,
                model.Note,
                userId);


            if (model.Image.HasValidImage())
            {
                var imageName = model.Image.SaveImage(businessId, model.Type.ToString(), model.Name, BusinessImagesPath);
                await this.businesses.SetImage(businessId, imageName);
            }

            this.TempData.AddSuccessMessage(string.Format(SuccessfullAdd, model.Name));

            return(RedirectToAction(nameof(Index)));
        }