public ActionResult Create(UserFormModel model) { var user = UserService.UserNew(); Csla.Data.DataMapper.Map(model, user, true); user.SetPassword(model.Password); try { user = UserService.UserSave(user); if (user.IsValid) { return new JsonResult { Data = this.Url.Action("Edit", new { id = user.UserId, message = Resources.SaveSuccessfulMessage }) }; } } catch (Exception ex) { this.ModelState.AddModelError("", ex.Message); } this.Map(user, model, false); return this.View(model); }
public ActionResult Details(int id) { var model = new UserFormModel(); var user = UserRepository.UserFetch(id); var startDate = DateTime.Now.AddDays(-48).ToStartOfWeek(Settings.StartDayOfWeek).Date; var endDate = DateTime.Now.ToStartOfWeek(Settings.StartDayOfWeek).Date.AddDays(6); var hours = HourRepository.HourFetchInfoList(user, startDate, endDate); model.User = user; model.ProjectListModel = new ProjectListModel { Projects = ProjectRepository.ProjectFetchInfoList(user) }; model.TimelineListModel = new TimelineListModel { Timelines = TimelineRepository.TimelineFetchInfoList(user), SourceId = model.User.SourceId, SourceTypeId = (int)model.User.SourceType, IsEditable = false }; model.CurrentWeekHourSummaryByDateListModel = new HourSummaryByDateListModel { User = user, Hours = this.FetchHoursForWeek( DateTime.Now.ToStartOfWeek(Settings.StartDayOfWeek), hours) }; model.TrailingWeeksHourSummaryByDateListModel = new HourSummaryByDateListModel { User = user, Hours = this.FetchHoursForTrailingWeeks( startDate, endDate, hours) }; model.Stories = StoryRepository.StoryFetchInfoList(model.User, false); var weeks = WeekCollection.GetWeeks(DateTime.Now.Year); hours = HourRepository.HourFetchInfoList( user, weeks.Min(row => row.StartDate), weeks.Max(row => row.EndDate)); var hourSummaries = new List<HourSummary>(); hourSummaries.Add(new HourSummary { Name = "Week", Value = (double)hours.Where(row => row.Date >= weeks.StartDate.Date && row.Date <= weeks.StartDate.AddDays(6)).Sum(row => row.Duration), NormalValue = 25 }); hourSummaries.Add(new HourSummary { Name = "Year", Value = (double)hours.Sum(row => row.Duration), NormalValue = 1250 }); model.HourSummaryListModel = new HourSummaryListModel { User = user, Hours = hourSummaries }; return this.View(model); }
public ActionResult Create() { var model = new UserFormModel(); try { var user = UserService.UserNew(); this.Map(user, model, true); } catch (Exception ex) { this.ModelState.AddModelError(string.Empty, ex.Message); } return this.View(model); }
public ActionResult Edit(int id, string message) { var model = new UserFormModel(); try { var user = UserService.UserFetch(id); model.Message = message; this.Map(user, model, true); } catch (Exception ex) { this.ModelState.AddModelError(string.Empty, ex.Message); } return this.View(model); }
public ActionResult Create(UserFormModel model) { return this.RedirectToAction("Details"); }
public ActionResult Create() { var model = new UserFormModel(); return this.View(model); }
public ActionResult Edit(int id, UserFormModel model) { var user = UserService.UserFetch(id); Csla.Data.DataMapper.Map(model, user, true); if (!string.IsNullOrEmpty(model.Password)) { user.SetPassword(model.Password); } user = UserService.UserSave(user); if (user.IsValid) { model.Message = Resources.SaveSuccessfulMessage; } this.Map(user, model, true); return this.View(model); }
public UserFormModel Map(User user, UserFormModel model, bool ignoreBrokenRules) { Csla.Data.DataMapper.Map(user, model, true); model.Tab = "User"; model.Roles = DataHelper.GetRoleList(); model.IsNew = user.IsNew; model.IsValid = user.IsValid; if (!user.IsNew) { model.NoteListModel = new NoteListModel { Source = user, Notes = NoteService.NoteFetchInfoList(user).AsQueryable() }; } if (!ignoreBrokenRules) { foreach (var brokenRule in user.BrokenRulesCollection) { this.ModelState.AddModelError(string.Empty, brokenRule.Description); } } if (!ignoreBrokenRules && !string.IsNullOrWhiteSpace(model.Password) && (model.Password != model.PasswordConfirmation)) { this.ModelState.AddModelError("Password", "Passwords must match."); this.ModelState.AddModelError("PasswordConfirmation", "Passwords must match."); this.ModelState.AddModelError(string.Empty, "Passwords must match."); } return model; }