public async Task <IActionResult> Add(ModAddModel inputModel) { if (inputModel == null || !ModelState.IsValid || inputModel.ModFile.Count != 1) { return(BadRequest()); } _logger.LogInformation($"Adding new mod to database. Name: '{inputModel.DisplayName}'"); var mod = await _modRepository.Add(inputModel); _logger.LogInformation($"Mod was added. Name: '{inputModel.DisplayName}'"); return(Ok(mod)); }
public IActionResult Index(ModAddModel model) { if (ModelState.IsValid) { MovieOnDemand movie = new MovieOnDemand { Movie = model.Movie, MovieTime = model.MovieTime, Status = _statusService.GetByName("Pending"), Customer = _cusService.GetByUser(_userManager.GetUserId(HttpContext.User)) }; _modservice.Add(movie); ViewBag.success = "success"; ViewBag.msg = "Your Request Has been send to Admin, Thank You"; ModelState.Clear(); return(View()); } return(View(model)); }
public async Task <Mod> Add(ModAddModel modAddModel) { string fileName = modAddModel.ModFile.First().FileName; string modFilePath = _environment.BuildPath(_pathOptions.ModDirectory, fileName); using (var file = File.Create(modFilePath)) { var stream = modAddModel.ModFile.First().OpenReadStream(); stream.Seek(0, SeekOrigin.Begin); await stream.CopyToAsync(file); } var mod = new Mod { DisplayName = modAddModel.DisplayName, Path = fileName }; await _context.Mods.AddAsync(mod); await _context.SaveChangesAsync(); return(mod); }