public void init_InputDocs() { InputGuest_Documents = new List<Guest_Documents>(); for (int i = 0; i < 3; i++) { Guest_Documents document = new Guest_Documents(); InputGuest_Documents.Add(document); }}
public IHttpActionResult PutGuest_Documents(int id, Guest_Documents guest_documents) { if (!ModelState.IsValid) { return BadRequest(ModelState); } if (id != guest_documents.Id) { return BadRequest(); } try { _Guest_DocumentsService.Update(guest_documents); } catch (DbUpdateConcurrencyException) { if (!Guest_DocumentsExists(id)) { return NotFound(); } else { throw; } } return StatusCode(HttpStatusCode.NoContent); }
public object BindModel( ControllerContext controllerContext, ModelBindingContext bindingContext, MemberDescriptor memberDescriptor) { List<Guest_Documents> res = new List<Guest_Documents>(); var form = controllerContext.HttpContext.Request.Form; int index = 0; while (!string.IsNullOrEmpty(form["Guest_DocumentsViewModel.Guest_Documents[" + index + "].Document_TypeId"])) { var model = new Guest_Documents(); if (!string.IsNullOrEmpty(form["Guest_DocumentsViewModel.Guest_Documents[" + index + "].Id"])) model.Id= int.Parse(form["Guest_DocumentsViewModel.Guest_Documents[" + index + "].Id"]); if (!string.IsNullOrEmpty(form["Guest_DocumentsViewModel.Guest_Documents[" + index + "].GuestId"])) model.GuestId = int.Parse(form["Guest_DocumentsViewModel.Guest_Documents[" + index + "].GuestId"]); if (!string.IsNullOrEmpty(form["Guest_DocumentsViewModel.Guest_Documents[" + index + "].DocumentURL"])) model.DocumentURL = form["Guest_DocumentsViewModel.Guest_Documents[" + index + "].DocumentURL"] ; if (!string.IsNullOrEmpty(form["Guest_DocumentsViewModel.Guest_Documents[" + index + "].Document_TypeId"])) model.Document_TypeId = int.Parse(form["Guest_DocumentsViewModel.Guest_Documents[" + index + "].Document_TypeId"]); res.Add(model); index++; } return res; }
public async Task UploadWholeFiles(Guest_DocumentsViewModel docsmodel, HttpContext context) { for (int i = 0; i < context.Request.Files.Count; i++) { var file = context.Request.Files[i]; if (file.FileName != "") { var a_document = docsmodel.InputGuest_Documents[i]; var dirpath = StorageRoot + GuestID + "\\"; if (!Directory.Exists(dirpath)) Directory.CreateDirectory(dirpath); if (a_document.Document_TypeId != 0) { var doc_type = await _Document_TypeRepository.GetById(a_document.Document_TypeId); var count = await _Guest_DocumentsRepository.CountByDocument_TypeId(GuestID.Value, a_document.Document_TypeId) + 1; var filename = doc_type.Name + "_" + count + Path.GetExtension(file.FileName); var fullPath = dirpath + filename; file.SaveAs(fullPath); Guest_Documents newdoc = new Guest_Documents(); newdoc.GuestId = GuestID.Value; newdoc.DocumentURL = StorageURL + GuestID.ToString() + "/" + filename; newdoc.Document_TypeId = a_document.Document_TypeId; await _Guest_DocumentsRepository.Create(newdoc); docsmodel.Guest_Documents.Add(newdoc); } } } }
public IHttpActionResult PostGuest_Documents(Guest_Documents guest_documents) { if (!ModelState.IsValid) { return BadRequest(ModelState); } _Guest_DocumentsService.Create(guest_documents); return CreatedAtRoute("DefaultApi", new { id = guest_documents.Id }, guest_documents); }