public void UpdateContentElement(int contentElementId, ContentElementDto contentElement) { var repo = new ContentElementRepository(); try { var factory = new ContentDomain.Factories.ContentElementFactory(); var ce = factory.Create(contentElement); var originalContentElement = repo.Get(contentElementId); foreach (var value in contentElement.TextContents) { originalContentElement.UpdateValue(factory.CreateTextContent(value)); } repo.Update(ce); } catch (Exception ex) { if (ex is ArgumentException || ex is ArgumentNullException) { throw new DomainException("Error occured when trying to insert ContentElement: " + ex.Message); } throw; } }
public void InsertNewContentElement(ContentElementDto contentElement) { var repo = new ContentElementRepository(); try { var ce = new ContentDomain.Factories.ContentElementFactory().Create(contentElement); repo.Insert(ce); } catch (Exception ex) { if (ex is ArgumentException || ex is ArgumentNullException) throw new DomainException("Error occured when trying to insert ContentElement: " + ex.Message); throw; } }
public ContentElementApiModule() : base("api/ContentElement") { Get["/"] = _ => { var list = new ContentElementRepository().All().AsDto(); return(Response.AsJson <IEnumerable <ContentElementDto> >(list)); }; Get["/{elementId}"] = arg => { var jsonModel = new ContentElementRepository().Get((int)arg.elementId).AsDto(); return(Response.AsJson <ContentElementDto>(jsonModel)); }; Post["/"] = _ => { var contentElement = this.Bind <ContentElementDto>(); var service = new ContentDomain.ApplicationServices.ContentElementService(); try { service.InsertNewContentElement(contentElement); return(HttpStatusCode.Created); } catch (DomainException ex) { return(Response.FromException(ex)); } }; Put["/{elementId}"] = args => { var contentElement = this.Bind <ContentElementDto>(); var service = new ContentDomain.ApplicationServices.ContentElementService(); try { service.UpdateContentElement((int)args.elementId, contentElement); return(HttpStatusCode.OK); } catch (DomainException ex) { return(Response.FromException(ex)); } }; }
public ContentElementApiModule() : base("api/ContentElement") { Get["/"] = _ => { var list = new ContentElementRepository().All().AsDto(); return Response.AsJson<IEnumerable<ContentElementDto>>(list); }; Get["/{elementId}"] = arg => { var jsonModel = new ContentElementRepository().Get((int)arg.elementId).AsDto(); return Response.AsJson<ContentElementDto>(jsonModel); }; Post["/"] = _ => { var contentElement = this.Bind<ContentElementDto>(); var service = new ContentDomain.ApplicationServices.ContentElementService(); try { service.InsertNewContentElement(contentElement); return HttpStatusCode.Created; } catch (DomainException ex) { return Response.FromException(ex); } }; Put["/{elementId}"] = args => { var contentElement = this.Bind<ContentElementDto>(); var service = new ContentDomain.ApplicationServices.ContentElementService(); try { service.UpdateContentElement((int)args.elementId, contentElement); return HttpStatusCode.OK; } catch (DomainException ex) { return Response.FromException(ex); } }; }
public void InsertNewContentElement(ContentElementDto contentElement) { var repo = new ContentElementRepository(); try { var ce = new ContentDomain.Factories.ContentElementFactory().Create(contentElement); repo.Insert(ce); } catch (Exception ex) { if (ex is ArgumentException || ex is ArgumentNullException) { throw new DomainException("Error occured when trying to insert ContentElement: " + ex.Message); } throw; } }
public void UpdateContentElement(int contentElementId, ContentElementDto contentElement) { var repo = new ContentElementRepository(); try { var factory = new ContentDomain.Factories.ContentElementFactory(); var ce = factory.Create(contentElement); var originalContentElement = repo.Get(contentElementId); foreach (var value in contentElement.TextContents) { originalContentElement.UpdateValue(factory.CreateTextContent(value)); } repo.Update(ce); } catch (Exception ex) { if (ex is ArgumentException || ex is ArgumentNullException) throw new DomainException("Error occured when trying to insert ContentElement: " + ex.Message); throw; } }