public static ViewModels.Archive ToViewModel(this Models.Archive model) { ViewModels.Archive result = null; if (model != null) { result = new ViewModels.Archive(); if (model.Collection != null) { result.Collection = model.Collection.ToViewModel(); } if (model.DateReleased != null) { result.DateReleased = (DateTime)model.DateReleased; } result.HtmlContent = model.HtmlContent; if (model.Id != null) { result.Id = model.Id.ToString(); } result.TextContent = model.TextContent; result.MinistryText = model.MinistryText; result.Title = model.Title; result.Preview = model.Preview; result.Body = model.Body; } return(result); }
public static Models.Archive FromViewModel(this ViewModels.Archive viewModel) { Models.Archive result = null; if (viewModel != null) { result = new Models.Archive(); if (viewModel.Collection != null) { result.Collection = viewModel.Collection.FromViewModel(); } if (viewModel.DateReleased != null) { result.DateReleased = (DateTime)viewModel.DateReleased; } result.HtmlContent = viewModel.HtmlContent; if (viewModel.Id != null) { result.Id = new ObjectId(viewModel.Id); } result.TextContent = viewModel.TextContent; result.MinistryText = viewModel.MinistryText; result.Title = viewModel.Title; result.Preview = viewModel.Preview; result.Body = viewModel.Body; } return(result); }
public IActionResult AddArchive([FromBody] ViewModels.Archive data) { Models.Archive newArchive = data.FromViewModel(); // first add the collection. ViewModels.Collection c = data.Collection; Models.Collection dbCollection = null; if (!string.IsNullOrEmpty(c.Id)) { dbCollection = db.GetCollection(new ObjectId(c.Id)); } else { // try to find it by searching other fields. dbCollection = db.GetCollection(c.StartDate, c.EndDate, c.Name); } if (dbCollection == null) { Models.Collection newCollection = c.FromViewModel(); dbCollection = db.CreateCollection(newCollection); } if (dbCollection != null) { newArchive.Collection = dbCollection; } db.CreateArchive(newArchive); return(new ObjectResult(newArchive.ToViewModel())); }
public IActionResult GetArchive(string archiveId) { ObjectId id = new ObjectId(archiveId); Models.Archive result = db.GetArchive(id); return(new ObjectResult(result.ToViewModel())); }
public FilePathResult Archive(int collageId) { Models.Archive archive = new Models.Archive(); string path = System.Web.HttpContext.Current.Server.MapPath("~\\App_Data\\Archive.xml"); XDocument doc = XDocument.Load(path); archive.Do_archive(collageId); return null; }
public FilePathResult Unarchive(int collageId) { Models.Archive archive = new Models.Archive(); string path = System.Web.HttpContext.Current.Server.MapPath("~\\App_Data\\Archive.xml"); XDocument doc = XDocument.Load(path); archive.Unarchive(collageId); return(null); }
public static AzureArchive ToAzure(this Models.Archive model) { var dto = new AzureArchive(); if (model != null) { dto.Id = model.Id.ToString(); } return(dto); }
/// <summary> /// Gets the post archive according to the given parameters. /// </summary> /// <param name="page">Optional page number</param> /// <param name="year">Optional year</param> /// <param name="month">Optional month</param> /// <returns>The archive</returns> public async Task<Models.Archive> GetArchiveAsync(int page = 1, int? year = null, int? month = null) { var model = new Models.Archive() { Year = year, Month = month }; var rep = new PostRepository(uow); DateTime? start = null; DateTime? stop = null; // Get start and stop dates if (year.HasValue) { start = new DateTime(year.Value, 1, 1); stop = start.Value.AddYears(1); if (month.HasValue) { start = new DateTime(year.Value, month.Value, 1); stop = start.Value.AddMonths(1); } model.TotalCount = await uow.Posts.Where(p => p.Published.HasValue && p.Published >= start && p.Published < stop).CountAsync(); } else { model.TotalCount = await uow.Posts.Where(p => p.Published.HasValue).CountAsync(); } // Calculate paging information model.PageSize = Config.Blog.ArchivePageSize; model.PageCount = Math.Max(Convert.ToInt32(Math.Ceiling(((double)model.TotalCount) / model.PageSize)), 1); model.CurrentPage = Math.Min(page, model.PageCount); // Get the posts if (start.HasValue) { model.Posts = await rep.GetAsync(p => p.Published.HasValue && p.Published >= start && p.Published < stop, model.CurrentPage * model.PageSize); } else { model.Posts = await rep.GetAsync(p => p.Published.HasValue, model.CurrentPage * model.PageSize); } // Filter out the current page model.Posts = model.Posts.Subset((model.CurrentPage - 1) * model.PageSize).ToList(); return model; }
public ActionResult Index(int id) { collageId = id; ViewBag.id = id; Models.Collage all = new Models.Collage(); List<Models.Story> storyList = new List<Models.Story>(); if (id == 0) { return View(all.storyList); } else { Models.Archive archive = new Models.Archive(); List<int> styId = new List<int>(); foreach (int a in archive.archiveList) { string collection = System.Web.HttpContext.Current.Server.MapPath("~\\App_Data\\StoryCollection.xml"); XDocument docu = XDocument.Load(collection); var cos = from s in doc.Elements("collages").Elements("collage") select s; foreach (var co in cos) { if (co.Element("id").Value == a.ToString()) { var ids = from s in co.Elements("storyId") select s; foreach (var sid in ids) { styId.Add(Int32.Parse(sid.Value)); } } } } var clgs = from collage in collection1.Element("collages") .Elements("collage") select collage; foreach (var clg in clgs) { if (clg.Element("id").Value == id.ToString()) { ViewBag.collageName = clg.Element("collageName").Value; var styids = from story in clg.Elements("storyId") select story; ViewBag.storyId = styids.First().Value; var s_in_c = from sty in doc.Element("collages").Elements("collage").Elements("story") select sty; foreach (var styid in styids) { foreach (var elem in s_in_c) { if (styid.Value == elem.Element("id").Value) { Models.Story c = new Models.Story(); c.id = Int32.Parse(elem.Element("id").Value); c.storyCaption = elem.Element("storyCaption").Value; c.storyTime = elem.Element("storyTime").Value; c.storyOrder = elem.Element("storyOrder").Value; storyList.Add(c); foreach (int i in styId) { if (i == c.id) { storyList.Remove(c); } } } } } return View(storyList); } } } return View(); }
public ActionResult Index(int id) { collageId = id; ViewBag.id = id; Models.Collage all = new Models.Collage(); List <Models.Story> storyList = new List <Models.Story>(); if (id == 0) { return(View(all.storyList)); } else { Models.Archive archive = new Models.Archive(); List <int> styId = new List <int>(); foreach (int a in archive.archiveList) { string collection = System.Web.HttpContext.Current.Server.MapPath("~\\App_Data\\StoryCollection.xml"); XDocument docu = XDocument.Load(collection); var cos = from s in doc.Elements("collages").Elements("collage") select s; foreach (var co in cos) { if (co.Element("id").Value == a.ToString()) { var ids = from s in co.Elements("storyId") select s; foreach (var sid in ids) { styId.Add(Int32.Parse(sid.Value)); } } } } var clgs = from collage in collection1.Element("collages") .Elements("collage") select collage; foreach (var clg in clgs) { if (clg.Element("id").Value == id.ToString()) { ViewBag.collageName = clg.Element("collageName").Value; var styids = from story in clg.Elements("storyId") select story; ViewBag.storyId = styids.First().Value; var s_in_c = from sty in doc.Element("collages").Elements("collage").Elements("story") select sty; foreach (var styid in styids) { foreach (var elem in s_in_c) { if (styid.Value == elem.Element("id").Value) { Models.Story c = new Models.Story(); c.id = Int32.Parse(elem.Element("id").Value); c.storyCaption = elem.Element("storyCaption").Value; c.storyTime = elem.Element("storyTime").Value; c.storyOrder = elem.Element("storyOrder").Value; storyList.Add(c); foreach (int i in styId) { if (i == c.id) { storyList.Remove(c); } } } } } return(View(storyList)); } } } return(View()); }
public void UpdateArchive(ObjectId id, Models.Archive archive) { var filter = new BsonDocument("Id", id); _db.GetCollection <Models.Archive>("Archives").ReplaceOne(filter, archive); }
public Models.Archive CreateArchive(Models.Archive archive) { _db.GetCollection <Models.Archive>("Archives").InsertOne(archive); return(archive); }