public async Task <ActionResult <DocumentInfoModel> > Post(DocumentInfoModel model, CancellationToken cancellationToken) { DocumentInfo entity = this._mapper.Map <DocumentInfo>(model); await this._uor.DocumentInfoRepository.AddAsync(entity, cancellationToken); await LoadEntityProperties(entity, cancellationToken); var newModel = this._mapper.Map <DocumentInfoModel>(entity); return(Ok(newModel)); }
public async Task <ActionResult <DocumentInfoModel> > Put(long id, DocumentInfoModel model, CancellationToken cancellationToken) { var entity = await this._uor.DocumentInfoRepository.GetByIdAsync(cancellationToken, id); this._mapper.Map(model, entity); await this._uor.DocumentInfoRepository.UpdateAsync(entity, cancellationToken); await LoadEntityProperties(entity, cancellationToken); var newModel = this._mapper.Map <DocumentInfoModel>(entity); return(Ok(newModel)); }
public ActionResult UploadFiles() { // Checking no of files injected in Request object if (Request.Files.Count > 0) { try { string[] allKeys = Request.Files.AllKeys[0].Split('|'); // var id = allKeys[0]; //var uploadNo = allKeys[0]; var uploadNo = "Tanasit"; //string folder = Server.MapPath("..\\FileUploads\\" + id + "\\" + uploadNo); string folder = Server.MapPath("..\\FileUploads\\" + uploadNo); // Get all files from Request object HttpFileCollectionBase files = Request.Files; for (int i = 0; i < files.Count; i++) { HttpPostedFileBase file = files[i]; string fname; // Checking for Internet Explorer if (Request.Browser.Browser.ToUpper() == "IE" || Request.Browser.Browser.ToUpper() == "INTERNETEXPLORER") { string[] testfiles = file.FileName.Split(new char[] { '\\' }); fname = testfiles[testfiles.Length - 1]; } else { fname = Guid.NewGuid().ToString(); } // Get the complete folder path and store the file inside it. CreateDocFolder(folder); FileInfo fi = new FileInfo(folder + "\\" + allKeys[0]); fname = Guid.NewGuid().ToString() + fi.Extension; fname = Path.Combine(folder + "\\", fname); file.SaveAs(fname); String sCreateDate = DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss"); DocumentInfoModel doc = new DocumentInfoModel(); doc.FileUID = Guid.NewGuid().ToString(); doc.FileName = allKeys[0]; doc.FilePath = fname; doc.CreateBy = "Tanasitj"; doc.CreateDate = sCreateDate; DocumentInfoRepo documentInfoRepo = new DocumentInfoRepo(); documentInfoRepo.Add(doc); } // Returns message that successfully uploaded return(Json("OK")); } catch (Exception ex) { return(Json(ex.Message)); } } else { return(Json("No files selected.")); } }