public void AdminSave() { bool isDuplicateUser = false; if (Administrator.UserId == null) { using (UserDAO dao = new UserDAO()) { isDuplicateUser = dao.IsDuplicateUserName(Administrator.Username); } } if (Administrator.ValidateModel() && !isDuplicateUser) { ((Shell.Admins)GetView(ManagerViews.Admins)).AdminData.IsEnabled = false; ((Shell.Admins)GetView(ManagerViews.Admins)).AdminGrid.IsEnabled = true; AdminList.Add(Administrator); NotifyOfPropertyChange(() => AdminList); ((Shell.Admins)GetView(ManagerViews.Admins)).AdminAddBar.Visibility = System.Windows.Visibility.Visible; ((Shell.Admins)GetView(ManagerViews.Admins)).AdminSaveBar.Visibility = System.Windows.Visibility.Collapsed; } if (isDuplicateUser) { Administrator.AddError("UserName", "Duplicate User Name not allowed."); } }
public int DoSaveUser(User user, Identification identification) { logger.Log(LogLevel.Trace, AppLib.GetCaller(logger)); //Validate Object if (!user.ValidateModel()) throw new FaultException<ServiceFault>(new ServiceFault(user.CurrentErrors), new FaultReason(SysVars.InvalidFormat)); if (user.UserId == null) { using (UserDAO dao = new UserDAO()) { if (dao.IsDuplicateUserName(user.Username)) throw new FaultException<ServiceFault>(new ServiceFault("Duplicate User Name", "Rejected"), new FaultReason("Duplicate User Name Found.")); } } using (UserDAO dao = new UserDAO()) { return dao.SaveUser(user, identification.Token, identification.UserId); } }