public JsonResult Count(int? id, string status) { try { using (var db = new MySelfieEntities()) { var query = db.Packets.AsQueryable(); if (status.IsNotEmptyOrNull()) query.Where(x => x.Status == status); if (id.HasValue) query = query.Where(x => x.WallId == id.Value); var count = query.Count(); return Json(new { count = count }, JsonRequestBehavior.AllowGet); } } catch (Exception ex) { Logger.Log(ex.ToString(), "error", User.Identity.Name, "API/Photo/Packet/List"); return Json(new { error = ex.ToString() }, JsonRequestBehavior.AllowGet); } }
public JsonResult List(int? id) { try { using (var db = new MySelfieEntities()) { var query = db.Packets.Where(x => x.Status != "deleted"); if (id.HasValue) query = query.Where(x => x.WallId == id.Value); query = query .OrderBy(x => x.StartTime); var packets = query.ToList(); return Json(new { packets = packets }, JsonRequestBehavior.AllowGet); } } catch (Exception ex) { Logger.Log(ex.ToString(), "error", User.Identity.Name, "API/Photo/Packet/List"); return Json(new { error = ex.ToString() }, JsonRequestBehavior.AllowGet); } }
public ActionResult Delete(int id) { if (id.IsLessThanOne()) { ModelState.AddModelError("missing_id", "Missing or Invalid ID"); return RedirectToAction("Index", "Wall"); } try { using (var db = new MySelfieEntities()) { var entity = db.Credentials.SingleOrDefault(x => x.CredentialId == id); if (entity.IsNotNull()) { db.SaveChanges(); } } } catch (Exception ex) { ModelState.AddModelError("ex", ex); Logger.Log(ex.ToString()); return View(); } return RedirectToRoute("credential_index_g"); }
public ActionResult Create(CredentialCreateModel model) { if (ModelState.IsValid) { try { using (var db = new MySelfieEntities()) { var entity = new Credential(); entity.MergeWithOtherType(model); db.Credentials.Add(entity); db.SaveChanges(); } } catch (Exception ex) { ModelState.AddModelError("ex", ex); return View(model); } return RedirectToRoute("credential_index_g"); } return View(model); }
public void Instagram(string code, int wallID) { using (var db = new MySelfieEntities()) { var wall = db.Walls.SingleOrDefault(x => x.WallId == wallID); if (wall.IsNotNull()) { var result = ""; try { var url = "https://api.instagram.com/oauth/access_token"; url += "?client_id=" + wall.Scrape_InstagramClientID; url += "&client_secret=" + wall.Scrape_InstagramClientSecret; url += "&grabt_type=authorization_code"; url += "&code=" + code; var uri = new Uri(url); var request = (HttpWebRequest)HttpWebRequest.Create(uri); request.Method = "POST"; using (var response = (HttpWebResponse)request.GetResponse()) { var stream = response.GetResponseStream(); var reader = new StreamReader(stream); result = reader.ReadToEnd(); reader.Close(); stream.Close(); } } catch (Exception ex) { Console.WriteLine(ex.ToString()); } var json = JsonConvert.DeserializeObject<dynamic>(result); wall.Scrape_InstagramToken = json.access_token; //wall.Scrape_InstagramUserName = json.user.username; } } }
public ActionResult Create(EventCreateModel model) { if (ModelState.IsValid) { try { using (var db = new MySelfieEntities()) { Event theEvent; if (model.EventId == 0) { theEvent = new Event(); theEvent.MergeWithOtherType(model); db.Events.Add(theEvent); } else { theEvent = db.Events.Where(x => x.EventId == model.EventId).FirstOrDefault(); theEvent.MergeWithOtherType(model); } db.SaveChanges(); } } catch (Exception ex) { ModelState.AddModelError("ex", ex); return View(model); } return RedirectToAction("Index", "Event"); } return View(model); }
public ActionResult Create(int id = 0) { EventCreateModel model = new EventCreateModel(); try { using (var db = new MySelfieEntities()) { Event theEvent; theEvent = db.Events.Where(x => x.EventId == id).FirstOrDefault(); model.MergeWithOtherType(theEvent); return View(model); } } catch (Exception) { // throw; } return View(); }
public ActionResult Index() { var model = new CredentialListViewModel(); try { using (var db = new MySelfieEntities()) { model.CredentialList = db.Credentials .Select(x => new CredentialListItemViewModel() { CredentialId = x.CredentialId, UserName = x.UserName, AppName = x.AppName, UsageToday = x.UsageToday }) .ToList(); } } catch (Exception ex) { ModelState.AddModelError("ex", ex); Logger.Log(ex.ToString()); } return View(model); }
public ActionResult Index() { var model = new WallListViewModel(); try { using (var db = new MySelfieEntities()) { //https://instagram.com/oauth/authorize/?scope=likes+relationships&response_type=code&redirect_uri=https%3A%2F%2Fapigee.com%2Foauth_callback%2Finstagram%2Foauth2CodeCallback&client_id=1fb234f05ed1496a9eb35458be5d2c5c var url_start = ""; url_start += "https://api.instagram.com/oath/authorize/"; url_start += "?client_id="; var url_end = "&redirect_uri=" + Url.Encode("http://myselfiest.azurewebsites.net/Auth/Instagram/"); url_end += "&response_type=code"; //url_end += "&state="; model.WallList = db.Walls .Where(x => x.Status != "deleted") .Select(x => new WallListItemViewModel() { Hashtag = x.Hashtag, Name = x.Name, TwitterUserName = x.TwitterUserName, Scrape_TwitterUserName = x.Scrape_TwitterUserName, WallId = x.WallId, IsActive = x.IsActive, Status = x.Status, PendingApproval = x.Photos.Where(y => y.HasPhoto == true).Count(y => y.Status == "new"), Instagram_Redirect_URL = url_start + x.Scrape_InstagramClientID + url_end // the wallID here goes to instagram and then back to our endpoint when we get the token }) .ToList(); } } catch (Exception ex) { ModelState.AddModelError("ex", ex); Logger.Log(ex.ToString(), "error", User.Identity.Name, "GET /Admin"); } return View(model); }
public ActionResult Edit(WallModel model) { if (ModelState.IsValid) { try { using (var db = new MySelfieEntities()) { var wall = db.Walls.Where(x => x.WallId == model.WallId).FirstOrDefault(); wall.MergeWithOtherType(model); if (model.CaptionText.IsEmptyOrNull()) wall.CaptionText = ""; if (model.DescriptionText.IsEmptyOrNull()) wall.DescriptionText = ""; if (model.RightText.IsEmptyOrNull()) wall.RightText = ""; if (model.Title.IsEmptyOrNull()) wall.Title = ""; if (model.LogoImageFile.HasFile()) { wall.LogoImage = model.LogoImageFile.getFileBytes(); // extracts bytes from posted file wall.LogoImageType = model.LogoImageFile.getFileType(); // extracts type from posted file } wall.IsActive = model.IsActive; wall.Scrape_InstagramToken = model.Scrape_InstagramToken; //Johnm - some mismatches on column naming, thus mergeWithOtherType not working wall.PostingAccount_InstagramToken = model.Post_InstagramToken; db.SaveChanges(); } } catch (Exception ex) { ModelState.AddModelError("ex", ex); Logger.Log(ex.ToString(), "error", User.Identity.Name, "POST /Wall/Edit/"); return View(model); } return RedirectToAction("Index", "Wall"); } return View(model); }
public ActionResult Delete(int id) { if (id.IsLessThanOne()) { ModelState.AddModelError("missing_id", "Missing or Invalid ID"); return RedirectToAction("Index", "Wall"); } try { using (var db = new MySelfieEntities()) { var entity = db.Walls.SingleOrDefault(x => x.WallId == id); if (entity != null) { entity.Status = "deleted"; entity.IsActive = false; db.SaveChanges(); } } } catch (Exception ex) { ModelState.AddModelError("ex", ex); Logger.Log(ex.ToString(), "error", User.Identity.Name, "GET /Wall/Delete/"); return View(); } return RedirectToAction("Index", "Wall"); }
// GET: Event public ActionResult Index() { IEnumerable<EventCreateModel> model; try { using (var db = new MySelfieEntities()) { model = db.Events.Select( x => new EventCreateModel() { EventId = x.EventId, Name = x.Name, StartDate = x.StartDate, EndDate = x.EndDate }).ToList(); } return View(model); } catch (Exception ex) { ModelState.AddModelError("ex", ex); } return View(); }
public JsonResult Remove(int id, string source) { if (source == "web") { using (var db = new MySelfieEntities()) { var entity = db.WebLogs.SingleOrDefault(x => x.WebLogId == id); if (entity.IsNotNull()) { entity.Status = "deleted"; db.SaveChanges(); return Json(new { id = id, success = true, source = source }); } else { return Json(new { id = id, success = false, error = "record not found" }); } } } if (source == "scraper") { using (var db = new MySelfieEntities()) { var entity = db.WorkerStatus.SingleOrDefault(x => x.WorkerStatusID == id); if (entity.IsNotNull()) { entity.Status = "deleted"; db.SaveChanges(); return Json(new { id = id, success = true, source = source }); } else { return Json(new { id = id, success = false, error = "record not found" }); } } } return Json(new { id = id, success = false, error = "invalid type" }); }
public ActionResult Edit(int id) { var model = new CredentialEditModel(); if (id.IsLessThanOne()) { ModelState.AddModelError("missing_id", "Missing or Invalid ID"); } try { using (var db = new MySelfieEntities()) { var entity = db.Credentials.SingleOrDefault(x => x.CredentialId == id); if (entity.IsNotNull()) { model.MergeWithOtherType(entity); return View(model); } } } catch (Exception ex) { ModelState.AddModelError("ex", ex); Logger.Log(ex.ToString()); } return View(model); }
public JsonResult Packet(int? id) { try { using (var db = new MySelfieEntities()) { var query = db.Packets.Where(x => x.Status == "new" || x.Status == "sent"); if (id.HasValue) query = query.Where(x => x.WallId == id.Value); query = query .OrderBy(x => x.StartTime) .Take(4); foreach (var entity in query.ToList()) { entity.Status = "sent"; } db.SaveChanges(); var packets = query.Select(x => new PhotoPacketModel { Data = x.JSONBody, PacketId = x.PacketId, Status = x.Status }) .ToArray(); var message = "Packets attempted to be pulled..." + Environment.NewLine + "Count: " + packets.Count() + Environment.NewLine + "Content-------------" + Environment.NewLine; foreach(var p in packets) { message += "Data: " + p.Data + Environment.NewLine; } Logger.Log(message, "update", User.Identity.Name, "API/Photo/Packet"); return Json(new { packets = packets }, JsonRequestBehavior.AllowGet); } } catch (Exception ex) { Logger.Log(ex.ToString(), "error", User.Identity.Name, "API/Photo/Packet"); return Json(new { error = ex.ToString() }, JsonRequestBehavior.AllowGet); } }
public JsonResult PacketStatus(PhotoPacketStatusChangeModel model) { try { var success = false; using (var db = new MySelfieEntities()) { var entity = db.Packets.SingleOrDefault(x => x.PacketId == model.PacketId); if (entity.IsNotNull()) { entity.Status = model.Status; db.SaveChanges(); success = true; } } return Json(new { success = success }); } catch (Exception ex) { Logger.Log(ex.ToString(), "error", User.Identity.Name, "API/Photo/Packet"); return Json(new { error = ex.ToString() }, JsonRequestBehavior.AllowGet); } }
public ActionResult Latest(LogListViewModel model) { if (model.FetchAmount.IsLessThanOne()) model.FetchAmount = 10; if (model.FetchSpeedInSeconds.IsLessThanOne()) model.FetchSpeedInSeconds = 5; model.LogList = new List<LogViewModel>(); using (var db = new MySelfieEntities()) { var combined = new List<LogViewModel>(); var query = db.WebLogs .Where(x => x.WebLogId > model.LastWebLogId) .Where(x => x.Status == "new") .OrderByDescending(x => x.TimeStamp) .Take(model.FetchAmount); var web = query.Select(x => new LogViewModel { Id = x.WebLogId, Message = x.Message, TimeStamp = x.TimeStamp, Type = x.Type, UserName = x.UserName, Context = x.Context, Source = "web", Header = "Web Log Data" }).ToList(); foreach (var log in web) { combined.Add(log); } var workerStatus = db.WorkerStatus .Where(x => x.WorkerStatusID > model.LastWorkerLogId) .Where(x => x.Status == "new") .OrderByDescending(x => x.TimeStamp) .Take(model.FetchAmount) .Select(x => new LogViewModel { Id = x.WorkerStatusID, Message = x.Message, TimeStamp = x.TimeStamp, Type = "update", UserName = "******", Source = "scraper", Header = "Scraper Log Data" }) .ToList(); foreach(var log in workerStatus) { combined.Add(log); } model.LogList = combined; if (web.Any()) model.LastWebLogId = web.Select(x => x.Id).Last(); if (workerStatus.Any()) model.LastWorkerLogId = workerStatus.Select(x => x.Id).Last(); return View(model); } }
public static async Task<bool> CreateBatch(int wallId) { bool result = false; //IList<Task> taskList = new List<Task>(); Wall wall = null; using (var db = new MySelfieEntities()) { var query = db.Photos .Where(x => x.WallId == wallId) .Where(x => x.Status == "approved") .OrderBy(x => x.ApprovedAt) .Take(9); var results = query.Select(x => x.Filename).ToList(); if (results.Count == 9) { wall = db.Walls.Single(x => x.WallId == wallId); var existingPacketCount = db.Packets .Where(x => x.WallId == wallId) .Where(x => x.Status == "new") .Count(); var wallTotalSeconds = (wall.PhotoShownLengthSecond.Value * 9) + wall.AdShownLengthSecond; var secondsUntilStart = wallTotalSeconds * existingPacketCount; var packet = new[] { new { slides = results, sponsor = "Wall/Image/" + wall.WallId } }; try { var jss = new System.Web.Script.Serialization.JavaScriptSerializer(); var json = jss.Serialize(packet); var entity = new Packet { WallId = wallId, JSONBody = json, StartTime = DateTime.UtcNow.AddSeconds(secondsUntilStart.IfNotNull(x => x.Value)), EndTime = DateTime.UtcNow.AddSeconds(secondsUntilStart.IfNotNull(x => x.Value) + wallTotalSeconds.IfNotNull(x => x.Value)), DurationMillisecond = wallTotalSeconds.IfNotNull(x => x.Value) * 1000, Status = "new", CreatedAt = DateTime.UtcNow }; db.Packets.Add(entity); string message = "Created new packet: " + Environment.NewLine + "WallId: " + entity.WallId + Environment.NewLine + "JSONBody: " + entity.JSONBody + Environment.NewLine + "StartTime: " + entity.StartTime + Environment.NewLine + "EndTime: " + entity.EndTime + Environment.NewLine + "DurationMillisecond: " + entity.DurationMillisecond + Environment.NewLine + "CreatedAt: " + entity.CreatedAt + Environment.NewLine; Logger.Log(message, "info", "system", "creating a packet", "Packet Created", db, false); var context = GetTwitterContext(new WallModel(wall)); foreach (var photo in query) { photo.Status = "packed"; photo.Packet = entity; //Johnm -- comment sending now a separate process from batching /* if (photo.Source == "Twitter") { await PhotoStatusChangeModel.PublishTweet(photo.Username, entity.StartTime, wall.RetweetMessage, context); } if (photo.Source == "Instagram") { PhotoStatusChangeModel.PublishInstagramComment(photo.Username, entity.StartTime, wall.RetweetMessage, wall.PostingAccount_InstagramToken, photo.SocialIDstring); } */ } db.SaveChanges(); } catch(Exception ex) { Logger.Log(ex.ToString(), "error", "system", "creating a packet", "Error creating packet", db, true); result = false; } result = true; } else { result = false; } } // end using db //if (result) // result is true when a packet was created //{ // var context = GetTwitterContext(new WallModel(wall)); // foreach (var photo in packetPhotos) // { // if (photo.Source == "Twitter") // { // var t = new Thread(() => PhotoStatusChangeModel.PublishTweet(photo.Username, newPacket.StartTime, wall.RetweetMessage, context)); // t.Start(); // } // if (photo.Source == "Instagram") // { // var t = new Thread(() => PhotoStatusChangeModel.PublishInstagramComment(photo.Username, newPacket.StartTime, wall.RetweetMessage, wall.PostingAccount_InstagramToken, photo.SocialIDstring)); // t.Start(); // } // } //} return result; }
public ActionResult CommentApproval(int? id) { var model = new PhotoApprovalViewModel(); if (id.HasValue) model.WallId = id.Value; model.FetchLatestAmount = 10; model.FetchLatestSpeedInSeconds = 4; try { using (var db = new MySelfieEntities()) { var wall = db.Walls .Where(x => x.WallId == model.WallId) .SingleOrDefault(); if (wall.IsNotNull()) { //model.FetchLatestAmount = wall. //model.FetchLatestSpeedInSeconds = } var query = db.Photos .Where(x => x.HasPhoto == true) .Where(x => x.Status == "packed"); if (id.HasValue) query = query.Where(x => x.WallId == id.Value); var results = query .OrderBy(x => x.CreatedAt) .Select(x => new PhotoViewModel { FileName = x.Filename, PhotoId = x.PhotoId, Text = x.Text, SocialId = x.SocialID, SocialCreated = x.SocialCreatedAt, UserScreenName = x.Username, Source = x.Source }) .Take(model.FetchLatestAmount) .ToList(); var photosLeft = db.Photos .Where(x => x.HasPhoto == true) .Where(x => x.Status == "packed") .Where(x => x.WallId == model.WallId) .Count(); var message = "Starting CommentApproval page." + Environment.NewLine + "WallID: " + model.WallId + Environment.NewLine + "New photos left: " + photosLeft + Environment.NewLine + "FetchLatestAmount: " + model.FetchLatestAmount + Environment.NewLine + "FetchLatestSpeedInSeconds: " + model.FetchLatestSpeedInSeconds + Environment.NewLine; Logger.Log(message, "update", User.Identity.Name, "/Photo/Latest"); if (results.Any()) { model.ImageList = results; model.LastPhotoTweetId = results.Select(x => x.PhotoId).Last(); return View(model); } else { model.ImageList = results; model.LastPhotoTweetId = 0; return View(model); } } } catch (Exception ex) { ModelState.AddModelError("ex", ex); Logger.Log(ex.ToString(), "error", User.Identity.Name, "/Admin/Photo/CommentApproval"); } return View(); }
public ActionResult LatestReadyForComments(int? id, PhotoApprovalViewModel model) { try { using (var db = new MySelfieEntities()) { if (model.IsNull()) model = new PhotoApprovalViewModel(); if (id.HasValue) model.LastPhotoTweetId = id.Value; if (model.FetchLatestAmount.IsLessThanOne()) model.FetchLatestAmount = 10; if (model.FetchLatestSpeedInSeconds.IsLessThanOne()) model.FetchLatestSpeedInSeconds = 5; var query = db.Photos .Where(x => x.HasPhoto == true) .Where(x => x.Status == "packed") //.Where(x => x.Source == "Twitter") .Where(x => x.PhotoId > model.LastPhotoTweetId); if (model.WallId > 0) query = query.Where(x => x.WallId == model.WallId); model.ImageList = query .OrderBy(x => x.CreatedAt) .Take(model.FetchLatestAmount) .Select(x => new PhotoViewModel { FileName = x.Filename, PhotoId = x.PhotoId, Text = x.Text, SocialId = x.SocialID, SocialCreated = x.SocialCreatedAt, UserScreenName = x.Username, Source = x.Source }) .ToList(); if (model.ImageList.Any()) { model.LastPhotoTweetId = model.ImageList.Select(x => x.PhotoId).Last(); } else { if (id.HasValue) { model.LastPhotoTweetId = id.Value; } } var photosLeft = db.Photos .Where(x => x.HasPhoto == true) .Where(x => x.Status == "packed") .Where(x => x.Source == "Twitter") .Where(x => x.WallId == model.WallId) .Count(); var message = "Got more images for comments." + Environment.NewLine + "WallID: " + model.WallId + Environment.NewLine + "New photos left: " + photosLeft + Environment.NewLine; //Logger.Log(message, "update", User.Identity.Name, "/Photo/Latest"); return View(model); } } catch (Exception ex) { ModelState.AddModelError("ex", ex); Logger.Log(ex.ToString(), "error", User.Identity.Name, "/Photo/LatestForComments"); return View(new PhotoApprovalViewModel()); } }
public async Task<JsonResult> SendComment(PhotoStatusChangeModel model) { try { using (var db = new MySelfieEntities()) { var photo = db.Photos.Single(x => x.PhotoId == model.PhotoTweetId); var wall = photo.Wall; string token = wall.PostingAccount_InstagramPassword; string id = photo.SocialIDstring; string template = wall.RetweetMessage; string username = photo.Username; //I should not have put all of this should not be in the controller, but the comment sending was really //Couple to the batch creation string response = ""; var success = true; if (photo.Source == "Twitter") { var context = PhotoStatusChangeModel.GetTwitterContext(new PhotoStatusChangeModel.WallModel(wall)); response = await PhotoStatusChangeModel.PublishTweet(photo.Username, DateTime.UtcNow, wall.RetweetMessage, context); } if (photo.Source == "Instagram") { response = PhotoStatusChangeModel.PublishInstagramComment(photo.Username, DateTime.UtcNow, wall.RetweetMessage, wall.PostingAccount_InstagramToken, photo.SocialIDstring); } if (response == "") { photo.Status = "commentSent"; } else { success = false; } db.SaveChanges(); var stuff = new { success = success, response = response }; return (Json(stuff)); } } catch (Exception ex) { Logger.Log(ex.ToString(), "error", User.Identity.Name, "/Photo/Status"); return Json(new { error = ex.ToString() }, JsonRequestBehavior.AllowGet); } }
public ActionResult Delete(int id) { EventCreateModel model = new EventCreateModel(); try { using (var db = new MySelfieEntities()) { Event theEvent; theEvent = db.Events.Where(x => x.EventId == id).FirstOrDefault(); db.Events.Remove(theEvent); db.SaveChanges(); return RedirectToAction("Index"); } } catch (Exception) { // throw; } return RedirectToAction("Index"); }
public JsonResult Stream(int? id) { try { using (var db = new MySelfieEntities()) { var query = db.Photos .Where(x => x.HasPhoto == true) .Where(x => x.Source == "Twitter") .Where(x => x.Status == "new"); if (id.HasValue) { query = query.Where(x => x.PhotoId > id); } var results = query .OrderBy(x => x.CreatedAt) .Take(10) .Select(x => new PhotoViewModel { FileName = x.Filename, PhotoId = x.PhotoId, Text = x.Text, SocialId = x.SocialID, SocialCreated = x.SocialCreatedAt, UserScreenName = x.Username }) .ToList(); return Json(new { data = results }, JsonRequestBehavior.AllowGet); } } catch (Exception ex) { Logger.Log(ex.ToString(), "error", User.Identity.Name, "/Photo/Stream"); return Json(new { error = ex.ToString() }, JsonRequestBehavior.AllowGet); } }
public ActionResult Edit(int id) { var model = new WallModel(); if (id.IsLessThanOne()) { ModelState.AddModelError("missing_id", "Missing or Invalid ID"); } try { using (var db = new MySelfieEntities()) { var entity = db.Walls.SingleOrDefault(x => x.WallId == id); if (entity.IsNotNull()) { model.MergeWithOtherType(entity); model.LogoImage = entity.LogoImage; //Johnm - some mismatches on column naming, thus mergeWithOtherType not working model.Post_InstagramToken = entity.PostingAccount_InstagramToken; return View(model); } } } catch (Exception ex) { Logger.Log(ex.ToString(), "error", User.Identity.Name, "GET /Wall/Edit/"); ModelState.AddModelError("ex", ex); Logger.Log(ex.ToString()); } return View(model); }
public async Task<JsonResult> Status(PhotoStatusChangeModel model) { try { using (var db = new MySelfieEntities()) { var entity = db.Photos.Single(x => x.PhotoId == model.PhotoTweetId); entity.Status = model.Status; entity.Approved = model.Approved; entity.ApprovedAt = DateTime.UtcNow; db.SaveChanges(); if (model.Status == "approved") { //var t = new Thread(() => PhotoStatusChangeModel.CreateBatch(model.WallId)); //t.Start(); //await PhotoStatusChangeModel.CreateBatch(model.WallId); await PhotoStatusChangeModel.CreateBatch(model.WallId); } Logger.Log("PhotoID " + model.PhotoTweetId.ToString() + " status changed to: " + model.Status, "info", User.Identity.Name, "/Photo/Status"); return Json(new { data = new PhotoViewModel(entity), success = true }, JsonRequestBehavior.AllowGet); } } catch (Exception ex) { Logger.Log(ex.ToString(), "error", User.Identity.Name, "/Photo/Status"); return Json(new { error = ex.ToString() }, JsonRequestBehavior.AllowGet); } }
public FileResult Image(int id) { try { using (var db = new MySelfieEntities()) { var wall = db.Walls.Where(x => x.WallId == id).FirstOrDefault(); if (wall.IsNotNull()) { return new FileStreamResult(new MemoryStream(wall.LogoImage), wall.LogoImageType); } } } catch (Exception ex) { Logger.Log(ex.ToString(), "error", User.Identity.Name, "GET /Wall/Image/"); ModelState.AddModelError("ex", ex); Logger.Log(ex.ToString()); } var fileName = "error.jpg"; var path = Path.Combine(Server.MapPath("~/Images"), fileName); return new FileStreamResult(new FileStream(path, FileMode.Open), "image/jpeg"); }
public ActionResult Viewer(int? id) { try { using (var db = new MySelfieEntities()) { var query = db.Packets .Where(x => x.Status == "new" || x.Status == "sent"); if (id.HasValue) { ViewBag.WallId = id.Value; var wall = db.Walls.Single(x => x.WallId == id.Value); wall.Status = "running"; ViewBag.Caption = wall.CaptionText; ViewBag.Title = wall.Title; ViewBag.Left = wall.DescriptionText; ViewBag.Right = wall.RightText; ViewBag.TopColor = wall.FrameTopColor; ViewBag.BottomColor = wall.FrameBottomColor; ViewBag.Interval = wall.PhotoShownLengthSecond * 1000; ViewBag.AnimationDuration = 800; ViewBag.GridShowDuration = 500; ViewBag.GridStagger = 170; ViewBag.FinalInterval = wall.AdShownLengthSecond * 1000; query = query.Where(x => x.WallId == id.Value); } query = query .OrderBy(x => x.StartTime); var entity = query.First(); entity.Status = "viewed"; var packets = query.Select(x => new PhotoPacketModel { Data = x.JSONBody, PacketId = x.PacketId, Status = x.Status }) .ToArray(); db.SaveChanges(); var message = "Viewer started!" + Environment.NewLine + "WallID: " + ViewBag.WallId + Environment.NewLine + "Caption: " + ViewBag.Caption + Environment.NewLine + "Title: " + ViewBag.Title + Environment.NewLine + "Left: " + ViewBag.Left + Environment.NewLine + "Right: " + ViewBag.Right + Environment.NewLine + "TopColor" + ViewBag.TopColor + Environment.NewLine + "BottomColor" + ViewBag.BottomColor + Environment.NewLine + "Interval" + ViewBag.Interval + Environment.NewLine + "AnimationDuration: " + ViewBag.AnimationDuration + Environment.NewLine + "GridShowDuration: " + ViewBag.GridShowDuration + Environment.NewLine + "GridStagger: " + ViewBag.GridStagger + Environment.NewLine + "FinalInterval: " + ViewBag.FinalInterval + Environment.NewLine; Logger.Log(message, "info", User.Identity.Name, "/Viewer"); return View(packets); } } catch (Exception ex) { ModelState.AddModelError("ex", ex); Logger.Log(ex.ToString(), "error", User.Identity.Name, "/Viewer"); } return View(); }
public ActionResult Create(WallModel model) { if (ModelState.IsValid) { using (var db = new MySelfieEntities()) { try { Wall wall; wall = new Wall(); wall.MergeWithOtherType(model); if (model.LogoPath.IsEmptyOrNull()) wall.LogoPath = ""; if (model.FrameTopColor.IsEmptyOrNull()) wall.FrameTopColor = "#DDDDDD"; if (model.FrameBottomColor.IsEmptyOrNull()) wall.FrameBottomColor = "#FFFFFF"; if (model.RetweetMessage.IsEmptyOrNull()) wall.RetweetMessage = ""; if (model.CaptionText.IsEmptyOrNull()) wall.CaptionText = ""; if (model.DescriptionText.IsEmptyOrNull()) wall.DescriptionText = ""; if (model.RightText.IsEmptyOrNull()) wall.RightText = ""; if (model.Title.IsEmptyOrNull()) wall.Title = ""; if (model.LogoImageFile.HasFile()) { wall.LogoImage = model.LogoImageFile.getFileBytes(); // extracts bytes from posted file wall.LogoImageType = model.LogoImageFile.getFileType(); // extracts type from posted file } //Johnm - some mismatches on column naming, thus mergeWithOtherType not working wall.PostingAccount_InstagramToken = model.Post_InstagramToken; wall.IsActive = false; wall.CreatedAt = DateTime.UtcNow; wall.Status = "new"; db.Walls.Add(wall); wall.Name = model.Name; db.SaveChanges(); } catch (DbEntityValidationException ex) { // Retrieve the error messages as a list of strings. var errorMessages = ex.EntityValidationErrors .SelectMany(x => x.ValidationErrors) .Select(x => x.ErrorMessage); // Join the list to a single string. var fullErrorMessage = string.Join("; ", errorMessages); // Combine the original exception message with the new one. var exceptionMessage = string.Concat(ex.Message, " The validation errors are: ", fullErrorMessage); Logger.Log(exceptionMessage, "error", User.Identity.Name, "POST /Wall/Create"); ModelState.AddModelError("ex", ex); return View(model); } catch (Exception ex) { Logger.Log(ex.ToString(), "error", User.Identity.Name, "POST /Wall/Create"); ModelState.AddModelError("ex", ex); return View(model); } } return RedirectToAction("Index", "Wall"); } return View(model); }
public ActionResult Edit(CredentialEditModel model) { if (ModelState.IsValid) { try { using (var db = new MySelfieEntities()) { var wall = db.Credentials.Where(x => x.CredentialId == model.CredentialId).FirstOrDefault(); wall.MergeWithOtherType(model); db.SaveChanges(); } } catch (Exception ex) { ModelState.AddModelError("ex", ex); Logger.Log(ex.ToString()); return View(model); } return RedirectToRoute("credential_index_g"); } return View(model); }