コード例 #1
0
        public ActionResult Create([Bind(Exclude="Id")]Task task)
        {
            try
            {
                using (var db = new TrackerDataContext())
                {
                    db.Task.InsertOnSubmit(task);
                    db.SubmitChanges();

                    var audit = new Audit(db.LastAudit);
                    audit.Task = task;
                    db.Audit.InsertOnSubmit(audit);
                    db.SubmitChanges();
                }
                return RedirectToAction("Edit", new { id = task.Id });
            }
            catch (BrokenRuleException e)
            {
                foreach (BrokenRule rule in e.BrokenRules)
                    ModelState.AddModelError(rule.Context.Rule.TargetProperty, rule.Message);
                return View(GetData());
            }
        }
コード例 #2
0
        public ActionResult AvatarPost(int id)
        {
            if (Request.Files.Count != 1)
            {
                using (var db = new TrackerDataContext())
                {
                    var user = db.User.GetByKey(id);
                    ModelState.AddModelError("file", "Must select a file to upload.");
                    return View("Edit", GetData(user));
                }
            }

            var file = Request.Files[0];
            var buffer = new byte[file.ContentLength];
            file.InputStream.Read(buffer, 0, buffer.Length);

            using (var db = new TrackerDataContext())
            {
                var user = db.User.GetByKey(id);
                user.Avatar = new Binary(buffer);
                user.AvatarType = file.ContentType;
                db.SubmitChanges();

                var audit = new Audit(db.LastAudit);
                audit.User = user;
                db.Audit.InsertOnSubmit(audit);
                db.SubmitChanges();
            }

            return RedirectToAction("Edit", new { id = id });
        }
コード例 #3
0
        public ActionResult UserEdit(int id)
        {
            User user = null;
            var userViewData = new UserViewData();
            try
            {
                using (var db = new TrackerDataContext())
                {
                    var options = new DataLoadOptions();
                    options.LoadWith<Data.User>(u => u.UserRoleList);
                    options.LoadWith<Data.UserRole>(u => u.Role);
                    db.LoadOptions = options;

                    user = db.User.GetByKey(id);
                    UpdateModel(user);

                    if (!db.GetChangeSet().Updates.Contains(user))
                    {
                        var ruleManager = new RuleManager();
                        ruleManager.Run(user);

                        if (ruleManager.BrokenRules.Count > 0)
                            throw new BrokenRuleException(ruleManager.BrokenRules);
                    }

                    db.SubmitChanges();

                    var audit = new Audit(db.LastAudit);
                    audit.User = user;
                    db.Audit.InsertOnSubmit(audit);
                    db.SubmitChanges();
                }
                return RedirectToAction("Edit", new { id = id });
            }
            catch (BrokenRuleException e)
            {
                if (user != null)
                    user.Detach();

                foreach (BrokenRule rule in e.BrokenRules)
                    ModelState.AddModelError(rule.Context.Rule.TargetProperty, rule.Message);
                return View(GetData(user));
            }
        }
コード例 #4
0
 private void OnAuditListRemove(Audit entity)
 {
     SendPropertyChanging(null);
     entity.Task = null;
     SendPropertyChanged(null);
 }
コード例 #5
0
 private void OnAuditListAdd(Audit entity)
 {
     SendPropertyChanging(null);
     entity.Task = this;
     SendPropertyChanged(null);
 }
コード例 #6
0
 private void OnAuditListRemove(Audit entity)
 {
     SendPropertyChanging(null);
     entity.User = null;
     SendPropertyChanged(null);
 }
コード例 #7
0
 private void OnAuditListAdd(Audit entity)
 {
     SendPropertyChanging(null);
     entity.User = this;
     SendPropertyChanged(null);
 }
コード例 #8
0
        public ActionResult EditPost(int id)
        {
            Task task = null;
            try
            {
                using (var db = new TrackerDataContext())
                {
                    var options = new DataLoadOptions();
                    options.LoadWith<Task>(t => t.CreatedUser);
                    db.LoadOptions = options;

                    task = db.Task.GetByKey(id);
                    UpdateModel(task);
                    db.SubmitChanges();

                    var audit = new Audit(db.LastAudit);
                    audit.Task = task;
                    db.Audit.InsertOnSubmit(audit);
                    db.SubmitChanges();
                }

                return RedirectToAction("Edit", new { id = task.Id });
            }
            catch (BrokenRuleException e)
            {
                foreach (BrokenRule rule in e.BrokenRules)
                    ModelState.AddModelError(rule.Context.Rule.TargetProperty, rule.Message);
                task.Detach();
                return View(GetData(task));
            }
        }