public ActionResult <Advert> Add([FromBody] Advert advert) { var ad = _advertService.Add(advert); var url = Url.Link("FindById", new { id = ad.Id }); return(Created(url, ad)); }
public async Task <IActionResult> CreateAdvert([FromBody] AdvertDto advertDto) { if (advertDto == null) { return(BadRequest()); } await _iAdvertService.Add(advertDto); return(Created("Created new advert", advertDto)); }
public async Task <ActionResult> Add(AdvertDto advert) { var ad = _mapper.Map <Advert>(advert); try { ad.Id = Guid.NewGuid().ToString(); ad.CreatedAt = DateTime.UtcNow; ad.Status = AdvertStatus.Pending; return(Ok(await _advertService.Add(ad))); } catch (Exception e) { return(BadRequest(e.Message)); } }
public async Task <ApiResult> Add([FromBody] AdverViewModel avm) { var res = new ApiResult(); if (!string.IsNullOrWhiteSpace(avm.Title) && avm.TypeID > 0) { try { Advert m = new Advert(); m.Title = avm.Title; m.TypeID = avm.TypeID; m.Pic = avm.Pic; m.BackgroundColor = avm.BackgroundColor; m.StartDate = C.DateTimes(avm.StartDate); m.EndDate = C.DateTimes(avm.EndDate); m.Url = avm.Url; m.Sorting = avm.Sorting; m.IsEnable = avm.IsEnable; if (avm.Pic != null) { //如有图片上传则保存到本地 if (avm.Pic.Contains("base64")) { string path = "UploadFiles/advert/"; string path2 = Utility.HostAddress + "advert\\"; m.Pic = ImagesUtility.Base64StringToFile(avm.Pic, path2, DateTime.Now.ToString("yyyyMMddHHmmssfff")); if (m.Pic != "") { m.Pic = path + m.Pic; } } } res.success = db.Add(m) > 0; } catch (Exception ex) { res.statusCode = (int)ApiEnum.Error; res.msg = ApiEnum.Error.GetEnumText() + ex.Message; } } return(await Task.Run(() => res)); }
public async Task <IActionResult> Create(AdvertModel model) { string recordId; try { recordId = await _advertService.Add(model); } catch (KeyNotFoundException) { return(new NotFoundResult()); } catch (Exception exc) { return(StatusCode(500, exc.Message)); } return(StatusCode(201, new CreateAdvertResponse { Id = recordId })); }
public HttpResponseMessage Post([FromBody] Advert advert) { if (advert == null) { return(Request.CreateResponse(System.Net.HttpStatusCode.BadRequest, $"Model is empty")); } try { var result = _advertService.Add(advert); return(Request.CreateResponse(System.Net.HttpStatusCode.OK, result)); } catch (ArgumentNullException exception) { return(Request.CreateResponse(System.Net.HttpStatusCode.BadRequest, exception.Message)); } catch (Exception exception) { return(Request.CreateResponse(System.Net.HttpStatusCode.InternalServerError, exception)); } }
public IActionResult AdvertAdd(Advert advert) { advert.ListingDate = DateTime.Now; var advertAdd = _advertService.Add(advert); if (ModelState.IsValid) { var filePath = Path.Combine(_hostEnvironment.WebRootPath, "resimler"); if (!Directory.Exists(filePath)) { Directory.CreateDirectory(filePath); } foreach (var item in advert.Files) { using (var fileStream = new FileStream(Path.Combine(filePath, item.FileName), FileMode.Create)) { item.CopyTo(fileStream); } advert.Photos.Add(new Photo { FileName = item.FileName, AdvertId = advert.Id }); } foreach (var photo in advert.Photos) { _photoService.Add(photo); } TempData["SuccessMessage"] = advertAdd.Message; return(RedirectToAction("AdvertList", "RealEstate")); } return(View()); }
public IActionResult PostAdvert(Advert advert) { _advertService.Add(advert); return(CreatedAtAction("GetAdvert", new { id = advert.Id }, advert)); }