public override PagedData ProcessRequest(HttpContext context, CookDBDataContext db, User u)
        {
            Project p = FetchObjectById <Project>(db.Projects, context, "project_id");

            if (p == null)
            {
                return(new PagedData("Invalid project id", false));
            }
            ProjectStatus o = (from a in p.ProjectStatus
                               where (a is T)
                               select a).OrderByDescending(a => a.Created.changed).FirstOrDefault();

            if (o != null)
            {
                return(new PagedData(o.getHistoryInfo()));
            }
            else
            {
                o = new T();
                p.ProjectStatus.Add(o);
                ProjectChangeHistory pch = new ProjectChangeHistory();
                pch.Project   = p;
                pch.ChangedBy = u.Contact;
                pch.message   = "Update status to " + ProjectChangeHistory.getSpacedName(this.GetType().Name.Remove(0, 3));
                o.Created     = pch;

                db.SubmitChanges();
                return(new PagedData(o.getHistoryInfo()));
            }
        }
        public override PagedData ProcessRequest(HttpContext context, CookDBDataContext db, User u)
        {
            Project p = FetchObjectById <Project>(db.Projects, context, "project_id", false);

            if (p == null)
            {
                return(new PagedData("Invalid project id", false));
            }

            T status;

            if (p.CurrentStatus == null || !(p.CurrentStatus is T))
            {
                status = new T();
                p.ProjectStatus.Add(status);
            }
            else
            {
                status = (T)p.CurrentStatus;
            }

            ProjectChangeHistory pch = ProcessStatusRequest(context, db, u, p, status);

            if (status.Created == null)
            {
                status.Created = pch;
            }

            db.SubmitChanges();
            return(new PagedData(status.created_change_id));
        }
        protected ProjectChangeHistory ProcessUpdateProjectRequest(HttpContext context, object update, Project p, User u)
        {
            ProjectChangeHistory pch = new ProjectChangeHistory();

            pch.message = ProcessUpdateRequest(context, update);
            if (pch.message.Length > 0)
            {
                pch.Project   = p;
                pch.ChangedBy = u.Contact;
                pch.addSummaryObject(this);
            }
            return(pch);
        }
        protected string updateArray <T>(string jsarr, List <T> cur, string comp, string[] values,
                                         string[] lprops, object[] links, Table <T> table, CookDBDataContext db, bool skipBlanks)
            where T : SetMethod, IGetId <T>, new()
        {
            bool   skip = skipBlanks;
            string msg  = "";

            if (jsarr == null || jsarr.Equals(""))
            {
                return(msg);
            }
            JArray arr = (JArray)JsonConvert.DeserializeObject(jsarr);
            T      def = new T();

            for (int i = 0; i < arr.Count(); i++)
            {
                string value = arr[i].Value <string>(comp);
                T      o     = null;
                if (!isNull(value))
                {
                    o    = cur.SingleOrDefault(def.compareIds(new string[] { value }));
                    skip = false; //got a value, create if not found
                }
                if (o == null && !skip)
                {
                    o = new T();
                    for (int j = 0; j < lprops.Length && j < links.Length; j++)
                    {
                        o.GetType().GetProperty(lprops[j]).GetSetMethod().Invoke(o, new object[] { links[j] });
                    }
                    msg += "\nNew " + ProjectChangeHistory.getSpacedName(o.GetType().Name) + " added:\n";
                }
                else if (o != null)
                {
                    cur.Remove(o);
                    msg += "\nUpdating existing " + ProjectChangeHistory.getSpacedName(o.GetType().Name) + ":\n";
                }

                if (o != null)
                {
                    foreach (string prop in values)
                    {
                        msg += o.SetProperty(db, prop, arr[i].Value <string>(prop));
                    }
                }
            }
            table.DeleteAllOnSubmit(cur);
            return(msg);
        }
예제 #5
0
        public override PagedData ProcessRequest(HttpContext context, CookDBDataContext db, User u)
        {
            Project p = FetchObjectById <Project>(db.Projects, context, "project_id");

            if (p == null)
            {
                return(new PagedData("Invalid project id", false));
            }

            ProjectChangeHistory pch = ProcessUpdateProjectArrayRequest <T, ProjectIngredient>(
                context.Request.Params.Get("ingredient_list"),
                p.ProjectIngredients.Where(a => a is T).ToList(),
                "ingredient_id", new string[] { "Project" }, new object[] { p },
                db.ProjectIngredients, p, u);

            db.SubmitChanges();
            return(new PagedData(""));
        }
        protected ProjectChangeHistory ProcessUpdateProjectArrayRequest <T, S>(string jsarr, List <S> cur,
                                                                               string comp, string[] lprops, object[] links, Table <S> table,
                                                                               Project p, User u)
            where T : class, S, new()
            where S : class, IGetId <S>
        {
            ProjectChangeHistory pch = new ProjectChangeHistory();

            pch.message = "";
            if (jsarr == null || jsarr.Equals(""))
            {
                return(pch);
            }
            JArray arr = (JArray)JsonConvert.DeserializeObject(jsarr);
            T      def = new T();

            for (int i = 0; i < arr.Count(); i++)
            {
                NameValueCollection map = new NameValueCollection();
                foreach (UpdateEntry ue in _dataMap)
                {
                    map.Set(ue.request_name, arr[i].Value <string>(ue.request_name));
                }

                string value = arr[i].Value <string>(comp);
                T      upd   = null;
                if (!isNull(value))
                {
                    upd = (T)cur.SingleOrDefault(def.compareIds(new string[] { value }));
                }
                if (upd == null)
                {
                    upd = new T();
                    for (int j = 0; j < lprops.Length && j < links.Length; j++)
                    {
                        upd.GetType().GetProperty(lprops[j]).GetSetMethod().Invoke(upd, new object[] { links[j] });
                    }
                    pch.message += "New " + ProjectChangeHistory.getSpacedName(upd.GetType().Name) + " added:\n";
                }

                else
                {
                    cur.Remove(upd);
                }

                string msg = ProcessUpdateRequest(map, upd);
                if (msg.Length > 0)
                {
                    pch.message += msg;
                    pch.message += "\n";
                }
            }
            if (table != null && cur.Count > 0)
            {
                pch.message += "Removed " + cur.Count + " entries\n";
                table.DeleteAllOnSubmit(cur);
            }

            if (pch.message.Length > 0)
            {
                pch.Project   = p;
                pch.ChangedBy = u.Contact;
                pch.addSummaryObject(this);
            }
            return(pch);
        }