public JsonResult Form(SeriesForm form, HttpPostedFileBase image, string imagePath) { if (image != null && image.ContentLength > 0) { var driveService = GoogleDriveService.GetDriveService(); var fileID = GoogleDriveService.uploadFile(driveService, image.InputStream, image.FileName, imagePath); form.ImageUrl = fileID; } return(SaveChanges(form, Facade <SeriesFacade>().AddSeries)); }
public int SaveChanges(SeriesForm form) { var tSeries = Table <Series>(); var series = tSeries.GetOrAdd(w => w.ID == form.ID); UpdateAuditFields(series, form.ByUserID); MapProperty(form, series, form.InlineEditProperty); // save SaveChanges(); return(series.ID); }
public IActionResult Put(int id, [FromBody] SeriesForm seriesForm) { try { if (ModelState.IsValid) { _repository.Update(id, new Series(seriesForm.Nom)); return(Ok()); } else { return(BadRequest()); } } catch (Exception ex) { return(StatusCode(StatusCodes.Status500InternalServerError)); } }
public int AddSeries(SeriesForm form) { using (var uow = UnitOfWorkFactory.Create <NovelContext>()) { var service = new SeriesService(uow); var id = service.SaveChanges(form); var connectorService = new ConnectorService(uow); if (form.Categories != null || form.InlineEditProperty == form.PropertyName(m => m.Categories)) { form.Categories = form.Categories ?? new List <int>(); var connectorForm = new GenericForm <Connector> { ByUserID = form.ByUserID, DataModel = new Connector { ConnectorType = R.ConnectorType.SERIES_TAGCATEGORY, SourceID = id } }; connectorService.Connect(connectorForm, form.Categories); } if (form.Genres != null || form.InlineEditProperty == form.PropertyName(m => m.Genres)) { form.Genres = form.Genres ?? new List <int>(); var connectorForm = new GenericForm <Connector> { ByUserID = form.ByUserID, DataModel = new Connector { ConnectorType = R.ConnectorType.SERIES_TAGGENRE, SourceID = id } }; connectorService.Connect(connectorForm, form.Genres); } if (form.Contains != null || form.InlineEditProperty == form.PropertyName(m => m.Contains)) { form.Contains = form.Contains ?? new List <int>(); var connectorForm = new GenericForm <Connector> { ByUserID = form.ByUserID, DataModel = new Connector { ConnectorType = R.ConnectorType.SERIES_TAGCONTAIN, SourceID = id } }; connectorService.Connect(connectorForm, form.Contains); } if (form.Feeds != null || form.InlineEditProperty == form.PropertyName(m => m.Feeds)) { var feedService = new FeedService(uow); foreach (var feed in form.Feeds) { feed.UrlHash = feed.Url.GetIntHash(); feed.Status = feed.Status == 0 ? R.FeedStatus.ACTIVE : feed.Status; feed.LastSuccessDate = feed.LastSuccessDate == DateTime.MinValue ? DateTime.Now : feed.LastSuccessDate; var feedForm = new GenericForm <Feed> { ByUserID = form.ByUserID, DataModel = feed }; var feedID = feedService.SaveChanges(feedForm); // add to connector only if it a new feed if (feed.ID == 0) { // connect series to feed var connectorForm = new ConnectorForm() { ByUserID = form.ByUserID, ConnectorType = R.ConnectorType.SERIES_FEED, SourceID = id, TargetID = feedID }; connectorService.SaveChanges(connectorForm); } } } if (form.Groups != null || form.InlineEditProperty == form.PropertyName(m => m.Groups)) { foreach (var group in form.Groups) { // connect series to feed var connectorForm = new ConnectorForm() { ByUserID = form.ByUserID, ConnectorType = R.ConnectorType.SERIES_GROUP, SourceID = id, TargetID = group.ID }; connectorService.SaveChanges(connectorForm); } } if (form.Authors != null || form.InlineEditProperty == form.PropertyName(m => m.Authors)) { foreach (var author in form.Authors) { // connect series to feed var connectorForm = new ConnectorForm() { ByUserID = form.ByUserID, ConnectorType = R.ConnectorType.SERIES_AUTHOR, SourceID = id, TargetID = author.ID }; connectorService.SaveChanges(connectorForm); } } if (form.Akas != null || form.InlineEditProperty == form.PropertyName(m => m.Akas)) { var akaService = new AkaService(uow); foreach (var aka in form.Akas) { var akaForm = new AkaForm { ByUserID = form.ByUserID, SourceID = form.ID, SourceTable = R.SourceTable.SERIES }; new PropertyMapper <Aka, AkaForm>(aka, akaForm).Map(); var akaID = akaService.SaveChanges(akaForm); } } return(id); } }