コード例 #1
0
        public async Task <IActionResult> Upload(AppoinmentViewModel model)
        {
            if (ModelState.IsValid)
            {
                bool exists = _db.AppoinmentLetters.Any(p => p.Username == model.Username);
                if (exists)
                {
                    ViewBag.Username = new SelectList(_userManager.Users, "UserName", "UserName", model.Username);
                    ModelState.AddModelError(string.Empty, "Appoinment letter already exists for this user.");
                    return(View(model));
                }

                string uniqueFiles = UploadedFile(model);

                AppoinmentLetter appoinment = new AppoinmentLetter
                {
                    CreatedBy   = User.Identity.Name,
                    CreatedDate = DateTime.Now,
                    Username    = model.Username,

                    URL = uniqueFiles
                };

                _db.AppoinmentLetters.Add(appoinment);

                await _db.SaveChangesAsync();

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

            ViewBag.Username = new SelectList(_userManager.Users, "UserName", "UserName", model.Username);

            return(View(model));
        }
コード例 #2
0
        public async Task CreateAppoinment(AppoinmentViewModel appoinmentViewModel)
        {
            await _appoinmentRepo.Create(new Core.Entities.Appointment
            {
                Capacity    = appoinmentViewModel.Capacity,
                Date        = appoinmentViewModel.Date,
                IsConfirmed = null
            });

            await _unitOfWork.Save();
        }
コード例 #3
0
        private string UploadedFile(AppoinmentViewModel model)
        {
            string uniqueFileName = null;

            if (model.AppoinmentLetterFile != null)
            {
                string uploadsFolder = Path.Combine(_webHostEnvironment.WebRootPath, "appoinmentletter");

                if (!System.IO.Directory.Exists(uploadsFolder))
                {
                    System.IO.Directory.CreateDirectory(uploadsFolder);
                }

                uniqueFileName = Guid.NewGuid().ToString() + "_" + model.AppoinmentLetterFile.FileName;

                string filePath = Path.Combine(uploadsFolder, uniqueFileName);

                using (var fileStream = new FileStream(filePath, FileMode.Create))
                {
                    model.AppoinmentLetterFile.CopyTo(fileStream);
                }
            }
            return(uniqueFileName);
        }
コード例 #4
0
 public ActionResult Create(AppoinmentViewModel viewModel)
 {
     _serviceRepo.CreateAppoinment(viewModel);
     return(View(new AppoinmentViewModel()));
 }