public ActionResult Create(VenderViewModel venderViewModel) { try { if (!ModelState.IsValid) { CountryController countryController = new CountryController(); ViewBag.Countries = countryController.Countries(); return(View(venderViewModel)); } else { var venderResult = new ServiceResponseModel(); if (venderViewModel.Id < 1) { venderViewModel.CreatedBy = Convert.ToInt32(Session["UserId"]); venderResult = webServices.Post(venderViewModel, "Vender/Add"); } else { venderViewModel.UpdatedBy = Convert.ToInt32(Session["UserId"]); venderResult = webServices.Post(venderViewModel, "Vender/Update"); } if (venderResult.StatusCode == System.Net.HttpStatusCode.Accepted) { var reuslt = (new JavaScriptSerializer().Deserialize <int>(venderResult.Data)); return(RedirectToAction(nameof(Index))); } if (Request.IsAjaxRequest()) { return(Json(venderViewModels, JsonRequestBehavior.AllowGet)); } return(View(venderViewModel)); } } catch (Exception ex) { throw ex; } }
public ActionResult CashCompanyCreate(CompnayModel compnayModel, HttpPostedFileBase LogoUrl) { try { if (!ModelState.IsValid) { CountryController countryController = new CountryController(); ViewBag.Countries = countryController.Countries(); return(View("CashCompany", compnayModel)); } else { using (HttpClient client = new HttpClient()) { using (var content = new MultipartFormDataContent()) { if (Request.Files.Count > 0) { if (LogoUrl != null) { var file = LogoUrl; byte[] fileBytes = new byte[file.InputStream.Length + 1]; file.InputStream.Read(fileBytes, 0, fileBytes.Length); var fileContent = new ByteArrayContent(fileBytes); fileContent.Headers.ContentDisposition = new System.Net.Http.Headers.ContentDispositionHeaderValue("LogoUrl") { FileName = file.FileName }; content.Add(fileContent); } } content.Add(new StringContent("ClientDocs"), "ClientDocs"); content.Add(new StringContent(compnayModel.Name ?? ""), "Name"); content.Add(new StringContent(compnayModel.Street ?? ""), "street"); content.Add(new StringContent(compnayModel.Postcode ?? ""), "Postcode"); content.Add(new StringContent(compnayModel.City ?? ""), "City"); content.Add(new StringContent(compnayModel.Street ?? ""), "State"); content.Add(new StringContent(compnayModel.Country ?? ""), "Country"); content.Add(new StringContent(compnayModel.Email ?? ""), "Email"); content.Add(new StringContent(compnayModel.Phone ?? ""), "Phone"); content.Add(new StringContent(compnayModel.Cell ?? ""), "Cell"); content.Add(new StringContent(compnayModel.OwnerRepresentaive ?? ""), "OwnerRepresentaive"); content.Add(new StringContent(compnayModel.Remarks ?? ""), "Commentes"); content.Add(new StringContent(compnayModel.TRN ?? ""), "TRN"); content.Add(new StringContent(compnayModel.Address ?? ""), "Address"); content.Add(new StringContent("true"), "IsCashCompany"); // var result1 = client.PostAsync("http://itmolen-001-site8.htempurl.com/api/Company/Add", content).Result; var result = webServices.PostMultiPart(content, "Company/Add", true); if (result.StatusCode == System.Net.HttpStatusCode.Accepted) { ViewBag.Message = "Created"; return(RedirectToAction(nameof(Index))); } else { ViewBag.Message = "Failed"; CountryController countryController = new CountryController(); ViewBag.Countries = countryController.Countries(); return(View("CashCompany", compnayModel)); } } } } } catch (Exception ex) { throw ex; } }