Exemple #1
0
        protected override void PerformActionProcess(IEngineContext engineContext, IController controller, IControllerContext controllerContext)
        {
            base.PerformActionProcess(engineContext, controller, controllerContext);

            var idVal = CommonOperationUtils.ReadPkFromParams(controllerContext.CustomActionParameters, engineContext.Request, ObtainPKProperty());

            controllerContext.PropertyBag["id"] = idVal;

            try
            {
                AssertIsPost(engineContext.Request.HttpMethod);

                var instance = ActiveRecordMediator.FindByPrimaryKey(Model.Type, idVal, true);

                controllerContext.PropertyBag["instance"] = instance;

                ActiveRecordMediator.DeleteAndFlush(instance);
            }
            catch (Exception ex)
            {
                controllerContext.PropertyBag["exception"] = ex;
            }
        }
Exemple #2
0
 public void DeleteAndFlush(T Entidade)
 {
     ActiveRecordMediator <T> .DeleteAndFlush(Entidade);
 }
        /// <summary> </summary>
        public void update([ARDataBind("item", Validate = true, AutoLoad = AutoLoadBehavior.NewRootInstanceIfInvalidKey)] posting item,
                           bool ajaxed_update,
                           bool forced_tmp,
                           string LongLength,
                           string Length,
                           string apply,
                           String pushlive,
                           string cancel,
                           String transition,
                           [ARDataBind("menuoptions", Validate = true, AutoLoad = AutoLoadBehavior.NewRootInstanceIfInvalidKey)] menu_option[] menuoptions
                           )
        {
            /*
             * 1.) test if there is any changes
             * 2.) save values
             * 3.) make copy version stuff
             * 4.) Move to the next page
             *
             */

            Flash["item"] = item;
            String poststr = httpService.get_post_str();

            if (item.baseid != 0 && formactionService.form_entry_match(item, poststr))
            {
                logger.writelog("The saved entry appered that same.  Nothing happened.", getView(), getAction(), item.baseid);
                Flash["message"] = "The saved entry appered that same.  Nothing happened.";
                if (apply != null || ajaxed_update)
                {
                    RedirectToReferrer();
                    return;
                }
                else
                {
                    item.editing = null;
                    ActiveRecordMediator <posting> .Save(item);

                    // ok this is where it gets merky.. come back to   Redirect(post.post_type.alias, "update", post); ?
                    Hashtable hashtable = new Hashtable();
                    hashtable.Add("post_type", item.post_type.alias);
                    Redirect("post", "posting_list", hashtable);
                }



                return;
            }

            //dynamic value;
            if (cancel != null)
            {
                if (forced_tmp && item.baseid != 0)
                {
                    logger.writelog("Canceled event creation", getView(), getAction());
                    ActiveRecordMediator <posting> .DeleteAndFlush(item);
                }
                else if (!forced_tmp)
                {
                    logger.writelog("Canceled event edit ", getView(), getAction(), item.baseid);
                    item.editing = null;
                    ActiveRecordMediator <posting> .Save(item);
                }
                Hashtable hashtable = new Hashtable();
                hashtable.Add("post_type", item.post_type.alias);
                Redirect("post", "posting_list", hashtable);
                return;
            }
            appuser user = userService.getUserFull();

            item.editing = user;
            if (String.IsNullOrWhiteSpace(item.name))
            {
                if (!forced_tmp)
                {
                    Flash["error"] = "You are missing the basic parts of: " + item.post_type.name;
                    RedirectToReferrer();
                    return;
                }
                else
                {
                    item.name = "TEMP NAME";
                }
            }
            if (String.IsNullOrWhiteSpace(item.name))
            {
                if (!forced_tmp)
                {
                    Flash["error"] = "You are missing the basic parts of: " + item.post_type.name;
                    RedirectToReferrer();
                    return;
                }
                else
                {
                    item.name = "TEMP NAME";
                }
            }
            if (!item.users.Contains(user))
            {
                item.users.Add(user);
            }

            if (menuoptions.Count() > 0)
            {
                IList <menu_option> tmplist = item.menuoptions;
                item.menuoptions.Clear();
                foreach (menu_option kill in tmplist)
                {
                    ActiveRecordMediator <menu_option> .DeleteAndFlush(kill);
                }

                foreach (menu_option menuitem in menuoptions)
                {
                    ActiveRecordMediator <menu_option> .Save(menuitem);

                    item.menuoptions.Add(menuitem);
                }
            }

            ActiveRecordMediator <posting> .Save(item);



            item.checksum = helperService.CalculateMD5Hash(poststr);
            if (item.baseid == 0)
            {
                //PlaceStatus stat = ActiveRecordBase<PlaceStatus>.Find(1);
                //events.Status = stat;
                item.creation_date = DateTime.Now;
            }
            else
            {
                item.updated_date = DateTime.Now;
            }



            item = versionService.make_post_revision(item);


            if (item != null && item.baseid > 0)
            {
                Flash["message"] = "revision made for " + item.name;
            }
            else
            {
                Flash["error"] = "Failed to revision of item.";
            }



            //Controllers.BaseController.theme



            // ok this is where it gets merky.. come back to   Redirect(post.post_type.alias, "update", post); ?

            //this will com later
            //Redirect(item.post_type.alias, "list");
            //for now just redirect to post list

            if (apply != null || ajaxed_update)
            {
                logger.writelog("Applied " + item.post_type.name + " edits", getView(), getAction(), item.baseid);
                Flash["message"] = "Applied " + item.post_type.name + " edits for " + item.name;
                if (item.baseid > 0)
                {
                    if (ajaxed_update)
                    {
                        CancelLayout();
                        RenderText(item.baseid.ToString());
                    }
                    else
                    {
                        RedirectToUrl("~/post/edit_post.castle?id=" + item.baseid);
                    }
                    return;
                }
                else
                {
                    RedirectToReferrer();
                    return;
                }
            }
            else
            {
                item.editing = null;
                logger.writelog("Saved " + item.post_type.name + " (Ver: " + item.version + " Rev: " + item.revision + ") edits on", getView(), getAction(), item.baseid);
                Flash["message"] = "Saved " + item.post_type.name + " edits for " + item.name;
                ActiveRecordMediator <posting> .Save(item);

                if (pushlive == "Push Live" && versionService.publish_post(item))
                {
                    logger.writelog("Published " + item.post_type.name + " edits on", getView(), getAction(), item.baseid);
                    Flash["message"] = "You have Saved and Published a " + item.post_type.name + " named " + item.name + "(" + item.baseid + ")";
                }
                else if (pushlive == "Push Live")
                {
                    logger.writelog("Failed to Publish " + item.post_type.name + " edits on", getView(), getAction(), item.baseid);
                    Flash["Error"] = "Opps, something failed by you Saved just not Published a " + item.post_type.name + " named " + item.name + "(" + item.baseid + ")";
                }

                // ok this is where it gets merky.. come back to   Redirect(post.post_type.alias, "update", post); ?
                Hashtable hashtable = new Hashtable();
                hashtable.Add("post_type", item.post_type.alias);
                Redirect("post", "posting_list", hashtable);
                return;
            }
        }