public void Restricted_CustomerInTwoGroups_PartiallyRestricted_NotRestricted_UpdateBug() { var customer = CreateCustomer("cust", profiles[0]); var profile = (ProfileDTO)profiles[0].Tag; SessionData data = CreateNewSession(profile, ClientInformation); CustomerGroupDTO group = new CustomerGroupDTO(); group.Name = "Children"; group.RestrictedType = CustomerGroupRestrictedType.Partially; group.MaxPersons = 10; group.Color = System.Drawing.Color.Aqua.ToColorString(); group.Customers.Add(customer.Map <CustomerDTO>()); CustomerGroupDTO savedGroup = null; RunServiceMethod(delegate(InternalBodyArchitectService service) { savedGroup = service.SaveCustomerGroup(data.Token, group); }); RunServiceMethod(delegate(InternalBodyArchitectService service) { savedGroup = service.SaveCustomerGroup(data.Token, savedGroup); }); var db = Session.QueryOver <Customer>().Fetch(x => x.Groups).Eager.SingleOrDefault(); Assert.AreEqual(1, db.Groups.Count); }
public void UpdateTwiceCustomerGroup_WithCustomer() { var customer = CreateCustomer("cust", profiles[0]); var profile = (ProfileDTO)profiles[0].Tag; SessionData data = CreateNewSession(profile, ClientInformation); CustomerGroupDTO group = new CustomerGroupDTO(); group.Name = "Children"; group.MaxPersons = 10; group.Color = System.Drawing.Color.Aqua.ToColorString(); group.Customers.Add(customer.Map <CustomerDTO>()); CustomerGroupDTO savedGroup = null; RunServiceMethod(delegate(InternalBodyArchitectService service) { savedGroup = service.SaveCustomerGroup(data.Token, group); }); RunServiceMethod(delegate(InternalBodyArchitectService service) { savedGroup = service.SaveCustomerGroup(data.Token, savedGroup); }); var db = Session.QueryOver <CustomerGroup>().SingleOrDefault(); Assert.AreEqual(1, db.Customers.Count); }
public void SimpeSaveNewCustomerGroup() { var profile = (ProfileDTO)profiles[0].Tag; SessionData data = CreateNewSession(profile, ClientInformation); CustomerGroupDTO group = new CustomerGroupDTO(); group.Name = "Children"; group.Color = System.Drawing.Color.Aqua.ToColorString(); group.MaxPersons = 10; CustomerGroupDTO savedGroup = null; RunServiceMethod(delegate(InternalBodyArchitectService service) { savedGroup = service.SaveCustomerGroup(data.Token, group); Assert.AreEqual(profile.GlobalId, savedGroup.ProfileId); group.ProfileId = savedGroup.ProfileId; Assert.AreNotEqual(Guid.Empty, savedGroup.GlobalId); Assert.AreEqual(1, savedGroup.Version); }); UnitTestHelper.CompareObjects(group, savedGroup, true); var db = Session.QueryOver <CustomerGroup>().SingleOrDefault(); Assert.AreEqual(profile.GlobalId, db.Profile.GlobalId); }
public void DeleteCustomerGroup(Token token, CustomerGroupDTO group) { var securityInfo = SecurityManager.EnsureAuthentication(token); var service = new CustomerGroupService(Session, securityInfo, Configuration); service.DeleteCustomerGroup(group); }
public void Restricted_CustomerInTwoGroups_NotRestricted_FullyRestricted() { var customer = CreateCustomer("cust", profiles[0]); var profile = (ProfileDTO)profiles[0].Tag; SessionData data = CreateNewSession(profile, ClientInformation); CustomerGroupDTO group = new CustomerGroupDTO(); group.Name = "Children"; group.Color = System.Drawing.Color.Aqua.ToColorString(); group.RestrictedType = CustomerGroupRestrictedType.None; group.MaxPersons = 10; group.Customers.Add(customer.Map <CustomerDTO>()); CustomerGroupDTO savedGroup = null; RunServiceMethod(delegate(InternalBodyArchitectService service) { savedGroup = service.SaveCustomerGroup(data.Token, group); }); group = new CustomerGroupDTO(); group.Name = "test"; group.RestrictedType = CustomerGroupRestrictedType.Full; group.MaxPersons = 10; group.Customers.Add(customer.Map <CustomerDTO>()); RunServiceMethod(delegate(InternalBodyArchitectService service) { service.SaveCustomerGroup(data.Token, group); }); }
public CustomerGroupDTO SaveCustomerGroup(Token token, CustomerGroupDTO customerGroup) { var securityInfo = SecurityManager.EnsureAuthentication(token); var service = new CustomerGroupService(Session, securityInfo, Configuration); return(service.SaveCustomerGroup(customerGroup)); }
public void SaveCustomerGroup_Validation_UniqueName_DifferentUser() { var profile = (ProfileDTO)profiles[0].Tag; var profile1 = (ProfileDTO)profiles[1].Tag; SessionData data = CreateNewSession(profile, ClientInformation); CustomerGroupDTO group = new CustomerGroupDTO(); group.Name = "Children"; group.MaxPersons = 10; group.Color = System.Drawing.Color.Aqua.ToColorString(); RunServiceMethod(delegate(InternalBodyArchitectService service) { service.SaveCustomerGroup(data.Token, group); }); data = CreateNewSession(profile1, ClientInformation); group = new CustomerGroupDTO(); group.Name = "Children"; group.Color = System.Drawing.Color.Aqua.ToColorString(); group.MaxPersons = 10; RunServiceMethod(delegate(InternalBodyArchitectService service) { service.SaveCustomerGroup(data.Token, group); }); Assert.AreEqual(2, Session.QueryOver <CustomerGroup>().RowCount()); }
public CustomerGroupDetailsViewModel(IBAWindow parentView, CustomerGroupDTO @group) { this.parentView = parentView; this.group = group; CollectionChangedEventManager.AddListener(CustomersReposidory.Instance, this); foreach (var customerDto in group.Customers) { members.Add(new GroupMemberItem(customerDto)); } fillCustomers(); ValidateCustomers(); ValidateMembers(); }
public void SaveNewCustomerGroup_WithCustomers_OtherProfile() { var customer = CreateCustomer("cust", profiles[1]); var profile = (ProfileDTO)profiles[0].Tag; SessionData data = CreateNewSession(profile, ClientInformation); CustomerGroupDTO group = new CustomerGroupDTO(); group.Name = "Children"; group.MaxPersons = 10; group.Customers.Add(customer.Map <CustomerDTO>()); RunServiceMethod(delegate(InternalBodyArchitectService service) { service.SaveCustomerGroup(data.Token, group); }); }
public void SaveNewCustomerGroup_WithDefaultActivity_OtherProfile() { var activity = CreateActivity("Activity", profiles[1]); var profile = (ProfileDTO)profiles[0].Tag; SessionData data = CreateNewSession(profile, ClientInformation); CustomerGroupDTO group = new CustomerGroupDTO(); group.Name = "Children"; group.MaxPersons = 10; group.DefaultActivityId = activity.GlobalId; RunServiceMethod(delegate(InternalBodyArchitectService service) { service.SaveCustomerGroup(data.Token, group); }); }
public void SaveNewCustomerGroup_DataInfo() { var profile = (ProfileDTO)profiles[0].Tag; SessionData data = CreateNewSession(profile, ClientInformation); CustomerGroupDTO group = new CustomerGroupDTO(); group.Name = "Children"; group.MaxPersons = 10; group.Color = System.Drawing.Color.Aqua.ToColorString(); var oldHash = profiles[0].DataInfo.CustomerGroupHash; RunServiceMethod(delegate(InternalBodyArchitectService service) { service.SaveCustomerGroup(data.Token, group); }); var dbProfile = Session.Get <Profile>(profile.GlobalId); Assert.AreNotEqual(oldHash, dbProfile.DataInfo.CustomerGroupHash); }
public void NewGroup() { if (!UIHelper.EnsureInstructorLicence()) { return; } var dlg = new EditDomainObjectWindow(); var ctrl = new usrCustomerGroupDetails(); dlg.SetControl(ctrl); var customer = new CustomerGroupDTO(); customer.Color = Color.LightGoldenrodYellow.ToColorString(); ctrl.Fill(customer); if (dlg.ShowDialog() == true) { CustomerGroupsReposidory.Instance.Add(ctrl.CustomerGroup); NotifyOfPropertyChange(() => Items); } }
public void SimpeSaveNewCustomerGroup_DefaultColor() { var profile = (ProfileDTO)profiles[0].Tag; SessionData data = CreateNewSession(profile, ClientInformation); CustomerGroupDTO group = new CustomerGroupDTO(); group.Name = "Children"; group.Color = null;//we don't set a color. server should set default color in this case group.MaxPersons = 10; CustomerGroupDTO savedGroup = null; RunServiceMethod(delegate(InternalBodyArchitectService service) { savedGroup = service.SaveCustomerGroup(data.Token, group); }); var db = Session.QueryOver <CustomerGroup>().SingleOrDefault(); Assert.AreEqual(Constants.DefaultColor, db.Color); Assert.AreEqual(Constants.DefaultColor, savedGroup.Color); }
public void SaveCustomerGroup_Validation_UniqueName() { var profile = (ProfileDTO)profiles[0].Tag; SessionData data = CreateNewSession(profile, ClientInformation); CustomerGroupDTO group = new CustomerGroupDTO(); group.Name = "Children"; group.MaxPersons = 10; group.Color = System.Drawing.Color.Aqua.ToColorString(); RunServiceMethod(delegate(InternalBodyArchitectService service) { service.SaveCustomerGroup(data.Token, group); }); group = new CustomerGroupDTO(); group.Name = "Children"; group.MaxPersons = 10; RunServiceMethod(delegate(InternalBodyArchitectService service) { service.SaveCustomerGroup(data.Token, group); }); }
public void DeleteCustomerGroup(CustomerGroupDTO customerGroup) { Log.WriteWarning("DeleteCustomerGroup: Username={0},GlobalId={1}", SecurityInfo.SessionData.Profile.UserName, customerGroup.GlobalId); if (!SecurityInfo.Licence.IsInstructor) { throw new LicenceException("This feature is allowed for Instructor account"); } var session = Session; using (var tx = session.BeginSaveTransaction()) { var dbGroup = session.Get <CustomerGroup>(customerGroup.GlobalId); if (SecurityInfo.SessionData.Profile.GlobalId != dbGroup.Profile.GlobalId) { throw new CrossProfileOperationException("Cannot modify customer group for another user"); } session.Delete(dbGroup); dbGroup.Profile.DataInfo.CustomerGroupHash = Guid.NewGuid(); tx.Commit(); } }
public void SaveNewCustomerGroup_WithDefaultActivity() { var activity = CreateActivity("Activity", profiles[0]); var profile = (ProfileDTO)profiles[0].Tag; SessionData data = CreateNewSession(profile, ClientInformation); CustomerGroupDTO group = new CustomerGroupDTO(); group.Name = "Children"; group.Color = System.Drawing.Color.Aqua.ToColorString(); group.MaxPersons = 10; group.DefaultActivityId = activity.GlobalId; CustomerGroupDTO savedGroup = null; RunServiceMethod(delegate(InternalBodyArchitectService service) { savedGroup = service.SaveCustomerGroup(data.Token, group); Assert.AreEqual(activity.GlobalId, savedGroup.DefaultActivityId); }); var db = Session.QueryOver <CustomerGroup>().SingleOrDefault(); Assert.AreEqual(activity.GlobalId, db.DefaultActivity.GlobalId); }
private void replace(CustomerGroupDTO selected, CustomerGroupDTO saved) { CustomerGroupsReposidory.Instance.Replace(selected, saved); SelectedItem = saved; NotifyOfPropertyChange(() => Items); }
public CustomerGroupDTO SaveCustomerGroup(Token token, CustomerGroupDTO customerGroup) { return(exceptionHandling(token, () => InternalService.SaveCustomerGroup(token, customerGroup))); }
public void Fill(CustomerGroupDTO customer) { Object = customer; }
public void DeleteCustomerGroup(Token token, CustomerGroupDTO group) { exceptionHandling(token, () => InternalService.DeleteCustomerGroup(token, @group)); }
public CustomerGroupDTO SaveCustomerGroup(CustomerGroupDTO customerGroup) { Log.WriteWarning("SaveCustomerGroup:Username={0},GlobalId={1}", SecurityInfo.SessionData.Profile.UserName, customerGroup.GlobalId); if (!SecurityInfo.Licence.IsInstructor) { throw new LicenceException("This feature is allowed for Instructor account"); } var db = customerGroup.Map <CustomerGroup>(); using (var trans = Session.BeginSaveTransaction()) { //Profile dbProfile = Session.Load<Profile>(SecurityInfo.SessionData.Profile.Id); //CustomerGroup db = null; //if (customerGroup.GlobalId != Constants.UnsavedGlobalId) //{ // db = Session.Get<CustomerGroup>(customerGroup.GlobalId); // Mapper.Map(customerGroup, db); //} //else //{ // db = customerGroup.Map<CustomerGroup>(); // db.CreationDate = Configuration.TimerService.UtcNow; // db.Profile = dbProfile; //} //if (SecurityInfo.SessionData.Profile.Id != db.Profile.Id) //{ // throw new CrossProfileOperationException("Cannot modify customer group for another user"); //} Profile dbProfile = Session.Load <Profile>(SecurityInfo.SessionData.Profile.GlobalId); if (db.IsNew) { db.CreationDate = Configuration.TimerService.UtcNow; } else { var dbGroup = Session.Get <CustomerGroup>(db.GlobalId); if (dbGroup != null) { if (dbProfile != dbGroup.Profile) { throw new CrossProfileOperationException("Cannot modify Group for another user"); } } } db.Profile = dbProfile; if (string.IsNullOrEmpty(db.Color)) { db.Color = Constants.DefaultColor; } if (customerGroup.DefaultActivityId.HasValue) { db.DefaultActivity = Session.Get <Activity>(customerGroup.DefaultActivityId.Value); if (SecurityInfo.SessionData.Profile.GlobalId != db.DefaultActivity.Profile.GlobalId) { throw new CrossProfileOperationException("Cannot modify customer group for another user"); } } int res = Session.QueryOver <CustomerGroup>().Where(x => x.Name == db.Name && x.GlobalId != db.GlobalId && x.Profile == dbProfile).RowCount(); if (res > 0) { throw new UniqueException("Customer group with the same name is already exist"); } db.Customers.Clear(); foreach (var customer in customerGroup.Customers) { var dbCustomer = Session.QueryOver <Customer>().Fetch(x => x.Groups).Eager.Where(x => x.GlobalId == customer.GlobalId).SingleOrDefault(); if (dbProfile != dbCustomer.Profile) { throw new CrossProfileOperationException("Cannot modify customer group for another user"); } if (dbCustomer.IsVirtual) { throw new InvalidOperationException("Cannot add virtual customer to the group"); } if (db.RestrictedType == CustomerGroupRestrictedType.Partially && dbCustomer.Groups.Where(x => x.RestrictedType != CustomerGroupRestrictedType.None && x.GlobalId != db.GlobalId).Count() > 0) { throw new AlreadyOccupiedException("Customer already belongs to partially or fully restricted group"); } if (db.RestrictedType == CustomerGroupRestrictedType.Full && dbCustomer.Groups.Count > 0) { throw new AlreadyOccupiedException("Customer already belongs to partially or fully restricted group"); } if (dbCustomer.Groups.Where(x => x.RestrictedType == CustomerGroupRestrictedType.Full).Count() > 0) { throw new AlreadyOccupiedException("Customer already belongs to partially or fully restricted group"); } db.Customers.Add(dbCustomer); } db = Session.Merge(db); dbProfile.DataInfo.CustomerGroupHash = Guid.NewGuid(); trans.Commit(); return(db.Map <CustomerGroupDTO>()); } }