示例#1
0
        public IActionResult EditRestaurantProfile()
        {
            string     userId     = HttpContext.User.GetUserId();
            Restaurant restaurant = _applicationService.GetRestaurantByUserId(userId);
            EditRestaurantProfileViewModel model = new EditRestaurantProfileViewModel()
            {
                Address        = restaurant.Address,
                Description    = restaurant.Description,
                PhoneNumber    = restaurant.PhoneNumber,
                RestaurantName = restaurant.RestaurantName,
                Website        = restaurant.Website,
                LogoPath       = restaurant.LogoPath,
                Interiors      = restaurant.Interiors
            };

            return(View(model));
        }
示例#2
0
        public async Task <IActionResult> EditRestaurantProfile(EditRestaurantProfileViewModel model, ICollection <IFormFile> logo, ICollection <IFormFile> files)
        {
            if (ModelState.IsValid)
            {
                var    uploads  = Path.Combine(_hostEnv.WebRootPath, "images\\logos\\");
                string logoPath = null;
                var    user     = await _userManager.FindByIdAsync(HttpContext.User.GetUserId());

                Restaurant restaurant = _applicationService.GetRestaurantByUserId(user.Id);
                foreach (var file in logo)
                {
                    var fileName = ContentDispositionHeaderValue.Parse(file.ContentDisposition).FileName.Trim('"');
                    var fnm      = restaurant.Email + ".png";
                    if (fileName.ToLower().EndsWith(".png") || fileName.ToLower().EndsWith(".jpg") || fileName.ToLower().EndsWith(".gif"))
                    {
                        var filePath  = Path.Combine(uploads, fnm);
                        var directory = new DirectoryInfo(uploads);
                        if (directory.Exists == false)
                        {
                            directory.Create();
                        }
                        await file.SaveAsAsync(filePath);

                        logoPath = "images/logos/" + fnm;
                    }
                }

                uploads = Path.Combine(_hostEnv.WebRootPath, "images\\interior\\");
                List <Interior> interiors = new List <Interior>();
                int             x         = 1;
                foreach (var file in files)
                {
                    var fileName = ContentDispositionHeaderValue.Parse(file.ContentDisposition).FileName.Trim('"');
                    var fnm      = restaurant.Email + x + ".png";
                    if (fileName.ToLower().EndsWith(".png") || fileName.ToLower().EndsWith(".jpg") || fileName.ToLower().EndsWith(".gif"))
                    {
                        var filePath  = Path.Combine(uploads, fnm);
                        var directory = new DirectoryInfo(uploads);
                        if (directory.Exists == false)
                        {
                            directory.Create();
                        }
                        await file.SaveAsAsync(filePath);

                        Interior interior = new Interior()
                        {
                            InteriorPath = "images/interior/" + fnm
                        };
                        interiors.Add(interior);
                        x++;
                    }
                }

                _applicationService.EditRestaurantProfileByUserId(user.Id, model.RestaurantName,
                                                                  model.Address, model.PhoneNumber, model.Website, model.Description, logoPath, interiors);

                TempData["Success"] = "Atnaujinta sėkmingai!";

                return(RedirectToAction("EditRestaurantProfile"));
            }

            return(View());
        }