Ejemplo n.º 1
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);
        }
Ejemplo n.º 2
0
        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);
        }
Ejemplo n.º 3
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);
        }
Ejemplo n.º 4
0
        public static TwitterContext GetTwitterContext(WallModel model)
        {
            var auth = new SingleUserAuthorizer
            {
                CredentialStore = new InMemoryCredentialStore
                {
                    ConsumerKey = model.ConsumerKey,
                    ConsumerSecret = model.ConsumerSecret,
                    OAuthToken = model.UserTokenKey,
                    OAuthTokenSecret = model.UserTokenSecret,
                }
            };

            auth.AuthorizeAsync();

            auth.AccessType = AuthAccessType.Write;

            return new TwitterContext(auth);
        }