public IHttpActionResult Put(Page page, Language language, long id, PageHighlightModel model) { var entity = highlightService.Get(x => x.PageTitle.Page == page && x.PageTitle.Language == language && x.Id == id); if (entity == null) { return(NotFound()); } Mapper.Map(model, entity, typeof(PageHighlightModel), typeof(PageHighlight)); if (model.MediaChange && !string.IsNullOrEmpty(model.MediaValue)) { entity.MediaValue = model.MediaValue; } if (model.MediaChange && !string.IsNullOrEmpty(entity.MediaValue) && (entity.MediaType == MediaType.Image || entity.MediaType == MediaType.File)) { var file = model.MediaValue.Split(';').First(); ChangeFileLocation(file, HttpContext.Current.Server.MapPath($"~/uploads/pagehighlight")); entity.MediaValue = "uploads/pagehighlight/" + file; } highlightService.Update(entity); return(Ok(Mapper.Map <PageHighlightModel>(entity))); }
public IHttpActionResult Post(Page page, Language language, PageHighlightModel model) { var parent = pageService.Get(x => x.Page == page && x.Language == language); if (parent == null) { return(NotFound()); } var entity = Mapper.Map <PageHighlight>(model); if (!string.IsNullOrEmpty(model.MediaValue)) { entity.MediaValue = model.MediaValue; } if (!string.IsNullOrEmpty(entity.MediaValue) && (entity.MediaType == MediaType.Image || entity.MediaType == MediaType.File)) { var file = model.MediaValue.Split(';').First(); ChangeFileLocation(file, HttpContext.Current.Server.MapPath($"~/uploads/pagehighlight")); entity.MediaValue = "uploads/pagehighlight/" + file; } parent.PageHighlights.Add(entity); pageService.Update(parent); return(Created($"http://{Request.RequestUri.Authority}/api/pages/{parent.Page}/highlights/{model.Id}", Mapper.Map <PageHighlightModel>(entity))); }