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()); } }
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 }); }
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)); } }
private void OnAuditListRemove(Audit entity) { SendPropertyChanging(null); entity.Task = null; SendPropertyChanged(null); }
private void OnAuditListAdd(Audit entity) { SendPropertyChanging(null); entity.Task = this; SendPropertyChanged(null); }
private void OnAuditListRemove(Audit entity) { SendPropertyChanging(null); entity.User = null; SendPropertyChanged(null); }
private void OnAuditListAdd(Audit entity) { SendPropertyChanging(null); entity.User = this; SendPropertyChanged(null); }
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)); } }