public async Task <string> SaveOperatorAttachmentAsync(OperatorAttachment attachment) { IRestClient client = new RestClient(ApiBaseUrl); var request = p_request; request.Method = Method.POST; request.Resource = "master/operator/saveattachment"; request.AddJsonBody(attachment); return(await Task.Run(() => { return ServiceResponse(client.Execute(request)); })); }
public async Task <JsonResult> AddAttachment() { var result = ""; try { foreach (string file in Request.Files) { var fileContent = Request.Files[file]; var operatorId = Request.Form[0]; var lookupId = Request.Form[1]; string mapPath = Server.MapPath("~/Attachments/"); if (!Directory.Exists(mapPath)) { Directory.CreateDirectory(mapPath); } fileContent.SaveAs(mapPath + fileContent.FileName); OperatorAttachment atttachment = new OperatorAttachment() { //attachmentId = operatorId + lookupId, //operatorId = operatorId, imagePath = fileContent.FileName, lookupCode = lookupId }; result = await new OperatorService(AUTHTOKEN, p_mobileNo).SaveOperatorAttachmentAsync(atttachment); } } catch (Exception ex) { throw ex; } return(Json(result, JsonRequestBehavior.AllowGet)); }
public async Task <ActionResult> SaveOperator(Operator OPerator) { OPerator.operatorAttachment = new List <OperatorAttachment>(); var lookupId = ""; foreach (string file in Request.Files) { var fileContent = Request.Files[file]; if (fileContent.ContentLength > 0) { if (file == "fadhar") { lookupId = "1375"; } if (file == "fpan") { lookupId = "1374"; } if (file == "flicense") { lookupId = "1376"; } if (file == "fvoter") { lookupId = "1377"; } if (file == "fothers") { lookupId = "1382"; } string mapPath = Server.MapPath("~/Attachments/"); if (!Directory.Exists(mapPath)) { Directory.CreateDirectory(mapPath); } fileContent.SaveAs(mapPath + fileContent.FileName); OperatorAttachment attachment = new OperatorAttachment() { imagePath = fileContent.FileName, lookupCode = lookupId }; OPerator.operatorAttachment.Add(attachment); } } //foreach (string file in Request.Files) //{ // var fileContent = Request.Files[file]; // if(file== "fadhar") // { // lookupId = "1375"; // } // if(file == "fpan") // { // lookupId = "1374"; // } // if(file == "flicense") // { // lookupId = "1376"; // } // if(file == "fvoter") // { // lookupId = "1377"; // } // if(file== "fothers") // { // lookupId = "1382"; // } // string mapPath = Server.MapPath("~/Attachments/"); // if (!Directory.Exists(mapPath)) // { // Directory.CreateDirectory(mapPath); // } // fileContent.SaveAs(mapPath + fileContent.FileName); // OperatorAttachment attachment = new OperatorAttachment() // { // imagePath = fileContent.FileName, // lookupCode = lookupId // }; // attachmentsList.Add(attachment); //} // OPerator.operatorAttachment = attachmentsList; //Operator o = new Operator(); //o.OperatorVehicle = new List<OperatorVehicle>(); //OPerator.OperatorVehicle.ForEach(x => //{ // x.VehicleType = //}); var result = await new OperatorService(AUTHTOKEN, p_mobileNo).SaveOperatorAsync(OPerator); return(RedirectToAction("Operator", "Operator")); }