コード例 #1
0
        public async Task <IActionResult> EditDeliveryMan(DeliveryMenViewModel dvm, IFormFile file)
        {
            var deliveryMan         = deliveryManService.GetDeliveryManById(dvm.DeliveryMan.Id);
            var deliveryManLocation = locationService.GetLocationById(dvm.DeliveryMan.Location.Id);

            deliveryMan.FirstName       = dvm.DeliveryMan.FirstName;
            deliveryMan.LastName        = dvm.DeliveryMan.LastName;
            deliveryMan.Phone           = dvm.DeliveryMan.Phone;
            deliveryManLocation.Address = dvm.DeliveryMan.Location.Address;
            deliveryManLocation.City    = dvm.DeliveryMan.Location.City;
            deliveryManLocation.ZipCode = dvm.DeliveryMan.Location.ZipCode;

            if (file != null)
            {
                //The picture has been changed
                //Upload the new picture
                var picturePath  = FileUploader.UploadImage(file, "DeliveryMenPictures");
                var pictureBytes = FileUploader.FileToBase64(picturePath);

                deliveryMan.PicturePath = picturePath;
                deliveryMan.ImageBase64 = pictureBytes;
            }

            if (deliveryMan.Email != dvm.DeliveryMan.Email)
            {
                //Email has been updated
                var user = await _userManager.FindByIdAsync(deliveryMan.IdentityId);

                if (user != null)
                {
                    user.Email                    = dvm.DeliveryMan.Email;
                    user.NormalizedEmail          = dvm.DeliveryMan.Email.ToUpper();
                    user.UserName                 = dvm.DeliveryMan.Email;
                    user.NormalizedUserName       = dvm.DeliveryMan.Email.ToUpper();
                    deliveryMan.Email             = dvm.DeliveryMan.Email;
                    deliveryMan.HasValidatedEmail = true;

                    await _userManager.UpdateAsync(user);
                }
            }


            deliveryMan.Location = deliveryManLocation;
            locationService.UpdateLocation(deliveryManLocation);
            deliveryManService.EditDeliveryMan(deliveryMan);


            TempData["Message"] = "Livreur modifié avec succès !";

            return(RedirectToAction("AllDeliveryMen"));
        }
コード例 #2
0
        public IActionResult AddCategory([Bind("Name,Description")] Category category, IFormFile file)
        {
            if (ModelState.IsValid)
            {
                string path = FileUploader.UploadImage(file, "CategoriesImages");

                //Convert to Base64
                byte[] base64 = FileUploader.FileToBase64(path);

                category.ImagePath   = path;
                category.ImageBase64 = base64;

                categoryService.AddCategory(category);
                TempData["Message"] = "Catégorie ajoutée avec succès !";
                return(RedirectToAction("AllCategories"));
            }
            return(View());
        }
コード例 #3
0
        public IActionResult EditCategory([Bind("Name, Description")] Category category, int Id, IFormFile file)
        {
            string imagePath = FileUploader.UploadImage(file, "CategoriesImages");

            //Convert to Base64
            byte[] base64 = FileUploader.FileToBase64(imagePath);

            var editedCategory = new Category
            {
                Description = category.Description,
                Id          = Id,
                ImagePath   = imagePath,
                Name        = category.Name,
                ImageBase64 = base64
            };

            categoryService.EditCategory(editedCategory);
            TempData["Message"] = "Catégorie modifiée avec succès !";

            return(RedirectToAction("AllCategories"));
        }