//Inventory attachement upload public IHttpActionResult Post() { int inventoryAttachmentId = 0; try { InventoryAttachmentModel inventoryAttachmentModel = new InventoryAttachmentModel(); var httpRequest = HttpContext.Current.Request; HttpFileCollection uploads = HttpContext.Current.Request.Files; foreach (string file in httpRequest.Files) { var docfiles = new List <string>(); var postedFile = httpRequest.Files[file]; var filePath = HttpContext.Current.Server.MapPath("~/InventoryImages/" + postedFile.FileName); postedFile.SaveAs(filePath); docfiles.Add(filePath); string filePaths = filePath; inventoryAttachmentModel.AttachmentPath = filePath; inventoryAttachmentModel.FileName = postedFile.FileName; inventoryAttachmentId = _inventoryServices.saveAttachement(inventoryAttachmentModel); } return(Ok(ResponseUtil.GetResponse(true, inventoryAttachmentId, null))); } catch (WebException ex) { var response = new FailureResponse() { Message = Messages.FAILURE_MESSAGE_CREATEUSER, StatusCode = 400 }; return(Content(HttpStatusCode.BadRequest, ResponseUtil.GetResponse(false, null, response))); } }
public int saveAttachement(InventoryAttachmentModel inventoryAttachmentModel) { InventoryAttachement inventoryAttachment = new InventoryAttachement(); inventoryAttachment.CreatedBy = 1; inventoryAttachment.ModifiedBy = 1; inventoryAttachment.CreatedDate = DateTime.Now; inventoryAttachment.ModifiedDate = DateTime.Now; inventoryAttachment.AttachmentPath = inventoryAttachmentModel.AttachmentPath; inventoryAttachment.FileName = inventoryAttachmentModel.FileName; InventoryAttachement inventory = _inventoryAttachmentRepository.Create(inventoryAttachment); _inventoryAttachmentRepository.SaveAsync(); InventoryAttachmentModel inventoryModelData = Mapper.Map <InventoryAttachement, InventoryAttachmentModel>(inventory); return((int)inventoryModelData.Id); }