Exemplo n.º 1
0
        public async Task <IActionResult> Create(CleaningStaffViewModel model)
        {
            if (ModelState.IsValid)
            {
                var cleaningStaff = new CleaningStaff
                {
                    FirstName = model.FirstName,
                    LastName  = model.LastName
                };
                if (model.ImageFile != null)
                {
                    cleaningStaff.ImageUrl = await _imageHelper.UploadImageAsync(model.ImageFile, model.FullName, "CleaningStaff");
                }
                _context.Add(cleaningStaff);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(model));
        }
Exemplo n.º 2
0
        public async Task <IActionResult> Edit(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            var cleaningStaff = await _context.CleaningStaffs.FindAsync(id);

            if (cleaningStaff == null)
            {
                return(NotFound());
            }
            var model = new CleaningStaffViewModel
            {
                Id        = cleaningStaff.Id,
                FirstName = cleaningStaff.FirstName,
                LastName  = cleaningStaff.LastName,
                ImageUrl  = cleaningStaff.ImageUrl
            };

            return(View(model));
        }
Exemplo n.º 3
0
        public async Task <IActionResult> Edit(CleaningStaffViewModel model)
        {
            if (ModelState.IsValid)
            {
                var cleaningStaff = await _context.CleaningStaffs.FindAsync(model.Id);

                if (cleaningStaff == null)
                {
                    return(NotFound());
                }

                cleaningStaff.FirstName = model.FirstName;
                cleaningStaff.LastName  = model.LastName;
                if (model.ImageFile != null)
                {
                    cleaningStaff.ImageUrl = await _imageHelper.UploadImageAsync(model.ImageFile, model.FullName, "CleaningStaff");
                }
                _context.Update(cleaningStaff);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(model));
        }
Exemplo n.º 4
0
        public IActionResult Create()
        {
            var model = new CleaningStaffViewModel();

            return(View());
        }