public async Task <IActionResult> Create(Mission mission, IFormFile file)
        {
            if (file != null)
            {
                var path   = Path.Combine(_environment.WebRootPath, "Photo", file.FileName);
                var stream = new FileStream(path, FileMode.Create);
                file.CopyTo(stream);
                mission.Photo = file.FileName;
            }

            mission.CreateDate = DateTime.Now;
            mission.User       = await _userManager.GetUserAsync(User);

            mission.CreateBy = await _userManager.GetUserNameAsync(mission.User);

            _missionService.Save(mission);


            return(RedirectToAction("Index", "mission"));
        }
Beispiel #2
0
 public ActionResult CreateMission(Mission mission)
 {
     if (ModelState.IsValid)
     {
         string message = MissionService.Save(mission, User.Identity.Name);
         if (string.IsNullOrEmpty(message))
         {
             TempData["Success"] = Messages.Created;
             return(RedirectToAction("Index"));
         }
         else
         {
             ViewData["Warning"] = message;
         }
     }
     else
     {
         ViewData["Error"] = Messages.InvalidField;
     }
     return(View());
 }