Beispiel #1
0
        public static void Update(Context db, int id, FDraft input, Func <TDraft, bool> permitting = null, Action <TDraft> after = null)
        {
            var draft = db.FormCoreDrafts.Where(x => x.Id == id).Include("Form").FirstOrDefault() as TDraft;

            if (null == draft)
            {
                throw new NotFound();
            }
            if (null != permitting && !permitting.Invoke(draft))
            {
                throw new AccessDenied();
            }
            draft.DataJson = JsonConvert.SerializeObject(input.Data);
            db.SaveChanges();
            after?.Invoke(draft);
        }
Beispiel #2
0
        public static int Create(Context db, FDraft input, Func <bool> before = null, Action <Draft> after = null)
        {
            if (null != before && !before.Invoke())
            {
                throw new AccessDenied();
            }
            var draft = new Draft {
                FormId   = input.FormId,
                DataJson = JsonConvert.SerializeObject(input.Data),
            };

            db.FormCoreDrafts.Add(draft);
            db.SaveChanges();
            if (typeof(TDraft) != typeof(Draft))
            {
                var sql = $"UPDATE TOP(1) dbo.FormCoreDrafts SET Discriminator='{typeof(TDraft).Name}' where Id={draft.Id}";
                db.Database.ExecuteSqlCommand(sql);
            }
            after?.Invoke(draft);
            return(draft.Id);
        }