Esempio n. 1
0
        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");
        }
Esempio n. 2
0
        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);
        }
Esempio n. 3
0
        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);
        }
Esempio n. 4
0
        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);
        }
Esempio n. 5
0
        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);
        }
Esempio n. 6
0
        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");
        }
Esempio n. 7
0
        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");
        }
Esempio n. 8
0
        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;
        }
Esempio n. 9
0
        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);
            }
        }
Esempio n. 10
0
        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);
            }
        }
Esempio n. 11
0
        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();
        }
Esempio n. 12
0
        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);
            }
        }
Esempio n. 13
0
        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);
            }
        }
Esempio n. 14
0
        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" });
        }
Esempio n. 15
0
        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);
        }