public IActionResult AddPhotoForCar([FromForm] UploadPhotoDto photoDto) { var result = _photoManager.Add(photoDto); if (result.Success) { return(Ok(result)); } return(BadRequest(result)); }
// POST: api/Photo public async Task <IHttpActionResult> Post() { // Check if the request contains multipart/form-data. if (!Request.Content.IsMimeMultipartContent("form-data")) { return(BadRequest("Unsupported media type")); } try { var photos = await photoManager.Add(Request); return(Ok(new { Message = "Photos uploaded ok", Photos = photos })); } catch (Exception ex) { return(BadRequest(ex.GetBaseException().Message)); } }
public async Task <IHttpActionResult> Post() { // Check if the request contains multipart/form-data. if (!Request.Content.IsMimeMultipartContent("form-data")) { return(BadRequest("Unsupported media type")); } dynamic report = null; Report myrep = null; ReportImage reportImage = null; //string lastName = string.Empty; foreach (var i in Request.RequestUri.ParseQueryString().AllKeys) { if (i.Equals("report")) { JObject myObjet = new JObject(); Request.RequestUri.TryReadQueryAsJson(out myObjet); int k = 0; foreach (var m in myObjet) { if (k == 0) { dynamic json = JValue.Parse(m.Value.ToString()); report = json.report; } else { dynamic userid = m.Value.ToString(); report.userId = userid; report.DateCreated = DateTime.Now; report.Status = false; report.imageCaption = "This is a supporting document"; myrep = new Report(); myrep.Alias = report.alias; myrep.CategoryId = report.categoryId; myrep.CityId = report.cityId; myrep.Company = report.company; myrep.contactbyMedia = report.contactbyMedia; myrep.CreditCard = report.creditCard; myrep.DateCreated = report.DateCreated; myrep.Email = report.email; myrep.ReportText = report.reportText; myrep.fax = report.fax; myrep.LocationTypeId = report.locationTypeId; myrep.OnlineTransaction = report.onlineTransaction; myrep.PhoneNo = report.phoneNumber; myrep.ripTerms = true; myrep.StateId = report.stateId; myrep.Status = report.Status; myrep.Street = report.street; myrep.TopicId = report.topicId; myrep.UserId = report.userId; myrep.WebSite = report.website; } k = k + 1; } } } ReportController reportCtr = new ReportController(); int reportiD = 0; await reportCtr.Post(myrep); reportiD = myrep.Id; rId = reportiD; try { dynamic photos = await photoManager.Add(Request, rId); int imageCount = photos.Count; foreach (var p in photos) { for (int i = 0; i < imageCount; i++) { reportImage = new ReportImage(); reportImage.ImagePath = p.Name; reportImage.ReportId = reportiD; reportImage.ImageCaption = report.imageCaption; } var result = imageRepository.Insert(reportImage); if (result.Status == RepositoryActionStatus.Created) { } } return(Ok(new { Message = "Photos uploaded ok", Photos = photos })); } catch (Exception ex) { return(BadRequest(ex.GetBaseException().Message)); } }