public IActionResult Post([FromBody] MediaModel mediaModel) { try { return(Ok(_mediaService.Add(mediaModel.ToDomainModel()))); //return NotFound(); } catch (Exception e) { ModelState.AddModelError("Post", e.Message); return(BadRequest(ModelState)); } }
public ActionResult Import(ImportModel model) { var file = Request.Files[0]; var fileName = file.FileName; var ext = Path.GetExtension(fileName); var virtualPath = string.Format("{0}/{1}/{2}/{3}{4}", "/Files", DateTime.Now.Year.ToString(), DateTime.Now.Month.ToString(), RandomIdGenerator.NewId(), ext); var absolutePath = Server.MapPath("~/") + virtualPath.Replace("/", "\\"); var dir = Path.GetDirectoryName(absolutePath); if (!Directory.Exists(dir)) { Directory.CreateDirectory(dir); } file.SaveAs(absolutePath); mediaService.Add(new UowMVC.Models.MediaViewModel { Name = model.File, Size = file.ContentLength, Type = (int)MediaTypeEnum.File, Extension = ext, RelavtivePath = virtualPath, ResourceDomain = WebConfig.ResourceDomain }); var dt = NPOIHelper.Import(absolutePath); if (dt == null || dt.Rows.Count == 0) { return(RedirectToAction("Index", "Result", new { state = false, message = "导入失败,没有读取到内容", style = "dialog" })); } var count = 0; foreach (DataRow row in dt.Rows) { var no = 0; int.TryParse(row[0].ToString(), out no); var name = row[1].ToString(); var description = row[2].ToString(); var department = new Department { No = no, Name = name, Description = description, }; uow.Set <Department>().Add(department); uow.Commit(); count++; } return(RedirectToAction("Index", "Result", new { state = true, message = "导入成功,共导入" + count + "条数据", style = "dialog" })); }
public async Task <IActionResult> Create(Media viewModel) { if (User.IsInRole(Roles.Client) || !User.Identity.IsAuthenticated) { return(NotFound()); } if (ModelState.IsValid) { var Id = await _mediaService.Add(viewModel); if (!String.IsNullOrEmpty(Request.Form["continue"])) { return(RedirectToAction("Edit", new { Id = Id })); } if (!String.IsNullOrEmpty(Request.Form["new"])) { return(RedirectToAction(nameof(Create))); } return(RedirectToAction(nameof(Index))); } return(View(viewModel)); }
public IActionResult Post([FromBody] Media Model) { return(Json( _mediaService.Add(Model) )); }
public Task <IResultModel> Add(MediaAddModel model) { return(_service.Add(model)); }
public async Task <IActionResult> AddBrandLink(MediaType mediaType, string link, string brandId) { var links = await _mediaService.Add(mediaType, link, new Guid(brandId)); return(PartialView("~/Views/Admin/Partials/_BrandLinks.cshtml", links)); }