Beispiel #1
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);
            }
        }
Beispiel #2
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);
            }
        }