static void DirectTest() { AssociateRM associateRM = CreateAssociate_AtlantaGasLight(); IEnumerable <AssociateRM> associates = GetListOfAssociates(); ContactRM contactRM = CreateContact_JoeFrancis(associateRM); UserRM userRM = CreateUserForContact(associateRM, contactRM); CustomerRM customerRM = CreateCustomer_WalMart(associateRM); OperatingContextRM operatingContextRM = GetOperatingContext(customerRM); OperatingContextRM operatingContextForAssociateRM = GetOperatingContextForAssociate(associateRM); SetUpAGLServicesAgent(); CreateUserForAgent(contactRM, associateRM); AssociateRM assetManagerRM = SetUpThirdPartyAssetManager(); SetUpAssociateAsPredecessor(); }
public void CreateAssociate() { var mapperConfig = new MapperConfiguration(cfg => { cfg.CreateMap <Associate, AssociateRM>(); }); IMapper mapper = new Mapper(mapperConfig); ILoggerFactory loggerFactory = new NullLoggerFactory(); ILogger <AssociateRepositoryEF> logger = new Logger <AssociateRepositoryEF>(loggerFactory); BusinessAssociatesContext context = new BusinessAssociatesContext(); AssociateRepositoryEF repository = new AssociateRepositoryEF(context, logger, mapper); AssociatesApplicationService appService = new AssociatesApplicationService(repository, mapper); // Set up Associate Debug.WriteLine("EFTEST: Setting up Internal Associate Atlanta Gas Light"); Commands.V1.Associate.Create createAssociateCommand = new Commands.V1.Associate.Create { AssociateTypeId = (int)AssociateTypeLookup.AssociateTypeEnum.InternalLDCFacility, DUNSNumber = _dunsNumber++, IsDeactivating = false, IsInternal = true, IsParent = false, LongName = "Atlanta Gas Light", ShortName = "AGL", StatusCodeId = (int)StatusCodeLookup.StatusCodeEnum.Active }; Debug.WriteLine("EFTEST: Getting AssociateRM"); AssociateRM associateRM = (AssociateRM)appService.Handle(createAssociateCommand).Result; // XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX // Set up Contact Debug.WriteLine("EFTEST: Setting up Joe Francis contact"); Commands.V1.Contact.Create createContactCommand = new Commands.V1.Contact.Create { PrimaryAddressId = 1, IsActive = true, PrimaryPhoneId = 1, LastName = "Francis", PrimaryEmailId = 1, FirstName = "Joe", Title = "Mr." }; Commands.V1.Contact.CreateForAssociate createContactForAssociateCommand = new Commands.V1.Contact.CreateForAssociate(associateRM.Id, createContactCommand); Debug.WriteLine("EFTEST: Getting ContactRM"); ContactRM contactRM = (ContactRM)appService.Handle(createContactForAssociateCommand).Result; // XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX Debug.WriteLine("EFTEST: Setting up Joe Francis contact"); Commands.V1.Contact.Address.Create createAddressCommand = new Commands.V1.Contact.Address.Create { StartDate = DateTime.Now, Address1 = "401 Bloombridge Way", AddressType = (int)AddressTypeLookup.AddressTypeEnum.Physical, Attention = "Joe Francis", City = "Marietta", Country = 1, GeographicState = 1, EndDate = DateTime.Now.AddYears(10), IsActive = true, Comments = "None", PostalCode = "30066", IsPrimary = true }; Commands.V1.Contact.Address.CreateForContact createAddressForContactCommand = new Commands.V1.Contact.Address.CreateForContact(contactRM.Id, createAddressCommand); Debug.WriteLine("EFTEST: Getting AddressRM"); // ReSharper disable once UnusedVariable AddressRM addressRM = (AddressRM)appService.Handle(createAddressForContactCommand).Result; // XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX // Set up User for Contact Debug.WriteLine("EFTEST: Setting up Joe Francis User from Joe Francis contact"); Commands.V1.User.Create createUserCommand = new Commands.V1.User.Create { ContactId = contactRM.Id, IDMSSID = "1", DepartmentCodeId = 1, HasEGMSAccess = true, IsActive = true, IsInternal = true }; Commands.V1.User.CreateForAssociate createUserForAssociateCommand = new Commands.V1.User.CreateForAssociate(associateRM.Id, createUserCommand); Debug.WriteLine("EFTEST: Getting UserRM"); // ReSharper disable once UnusedVariable UserRM userRM = (UserRM)appService.Handle(createUserForAssociateCommand).Result; // XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX // Set up Customer for Associate - can we get rid of this and just use relationship object Debug.WriteLine("EFTEST: Setting up WalMart customer for Associate"); Commands.V1.Customer.Create createCustomerCommand = new Commands.V1.Customer.Create { StartDate = DateTime.Now, AccountNumber = "12345678", AlternateCustomerId = 1, BalancingLevelId = 1, BasicPoolId = 1, ContractTypeId = 1, CurrentDemand = 1, DUNSNumber = _dunsNumber++, DailyInterruptible = 1, DeliveryLocationId = 1, DeliveryPressure = 1, CustomerTypeId = 1, DeliveryTypeId = 1, EndDate = DateTime.Now.AddYears(10), IsFederal = false, MDQ = 1, GroupTypeId = 1, LongName = "WalMart", TurnOffDate = DateTime.Now.AddYears(10), PreviousDemand = 1, SS1 = false, NominationLevelId = 1, MaxHourlyInterruptible = 1, NAICSCode = 1245, MaxDailyInterruptible = 1, StatusCodeId = 1, ShipperId = 1, HourlyInterruptible = 1, LDCId = 1, SICCode = 1, InterstateSpecifiedFirm = 1, TotalDailySpecifiedFirm = 1, ShortName = "WMT", SICCodePercentage = 1, ShippersLetterToDate = DateTime.Now.AddYears(1), IntrastateSpecifiedFirm = 1, MaxHourlySpecifiedFirm = 1, TotalHourlySpecifiedFirm = 1, ShippersLetterFromDate = DateTime.Now.AddYears(-1), LossTierTypeId = 1, TurnOnDate = DateTime.Now.AddYears(-1) }; Commands.V1.Customer.CreateForAssociate createCustomerForAssociateCommand = new Commands.V1.Customer.CreateForAssociate(associateRM.Id, createCustomerCommand); Debug.WriteLine("EFTEST: Getting CustomerRM"); // ReSharper disable once NotAccessedVariable CustomerRM customerRM = (CustomerRM)appService.Handle(createCustomerForAssociateCommand).Result; // XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX // Set Up Operating Context Commands.V1.OperatingContext.Create createOperatingContextCommand = new Commands.V1.OperatingContext.Create { ActingBATypeID = 1, PrimaryAddressId = 1, Status = 1, CertificationId = 1, OperatingContextType = 1, IsDeactivating = false, ThirdPartySupplierId = 1, FacilityId = 1, ProviderType = 1, LegacyId = 1, PrimaryPhoneId = 1, PrimaryEmailId = 1, StartDate = DateTime.Now }; Commands.V1.OperatingContext.CreateForCustomer createOperatingContextForCustomerCommand = new Commands.V1.OperatingContext.CreateForCustomer(customerRM.Id, createOperatingContextCommand); Debug.WriteLine("EFTEST: Getting OperatingContextRM for Customer"); // ReSharper disable once NotAccessedVariable // ReSharper disable once UnusedVariable OperatingContextRM operatingContextRM = (OperatingContextRM)appService.Handle(createOperatingContextForCustomerCommand).Result; // XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX // Set up relationship between Associate and OperatingContext Debug.WriteLine("EFTEST: Getting OperatingContextRM for Associate"); // ReSharper disable once NotAccessedVariable Commands.V1.OperatingContext.CreateForAssociate createOperatingContextForAssociateCommand = new Commands.V1.OperatingContext.CreateForAssociate(associateRM.Id, createOperatingContextCommand); // ReSharper disable once UnusedVariable OperatingContextRM operatingContextForAssociateRM = (OperatingContextRM)appService.Handle(createOperatingContextForAssociateCommand).Result; // XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX // Set up Associate as Agent // Set up Associate Debug.WriteLine("EFTEST: Setting up AGL Services Agent"); Commands.V1.Associate.Create createAssociateCommandForAgent = new Commands.V1.Associate.Create { AssociateTypeId = ExternalAssociateTypeLookup.ActingAssociateTypes[(int)ExternalAssociateTypeLookup.ExternalAssociateTypeEnum.AssetManager].ActingAssociateTypeId, DUNSNumber = _dunsNumber++, IsDeactivating = false, IsInternal = true, IsParent = false, LongName = "AGL Services", ShortName = "SCS", StatusCodeId = (int)StatusCodeLookup.StatusCodeEnum.Active }; Debug.WriteLine("EFTEST: Getting AssociateRM for Agent"); // ReSharper disable once NotAccessedVariable // ReSharper disable once UnusedVariable AssociateRM agentRM = (AssociateRM)appService.Handle(createAssociateCommandForAgent).Result; // XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX // AddAssociate User to Agent Debug.WriteLine("EFTEST: Create User for Agent"); Commands.V1.User.Create createUserCommandForAgent = new Commands.V1.User.Create { IsActive = true, IsInternal = true, ContactId = contactRM.Id, HasEGMSAccess = true, IDMSSID = "1", DeactivationDate = DateTime.Now.AddYears(10), DepartmentCodeId = 1 }; Commands.V1.User.CreateForAssociate createUserForAgent = new Commands.V1.User.CreateForAssociate(associateRM.Id, createUserCommandForAgent); Debug.WriteLine("EFTEST: Getting UserRM for Agent"); // ReSharper disable once NotAccessedVariable // ReSharper disable once UnusedVariable UserRM userRM2 = (UserRM)appService.Handle(createUserForAgent).Result; // XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX // Set up Asset Manager for Associate for Third-Party Suppliers Debug.WriteLine("EFTEST: Set up third party asset manager"); Commands.V1.Associate.Create createAssetManagerForTPS = new Commands.V1.Associate.Create { AssociateTypeId = ExternalAssociateTypeLookup.ActingAssociateTypes[(int)ExternalAssociateTypeLookup.ExternalAssociateTypeEnum.AssetManager].ActingAssociateTypeId, DUNSNumber = _dunsNumber++, IsDeactivating = false, IsInternal = true, IsParent = false, LongName = "AGL Services", ShortName = "SCS", StatusCodeId = (int)StatusCodeLookup.StatusCodeEnum.Active }; Debug.WriteLine("EFTEST: Get AssociateRM for third party"); // ReSharper disable once NotAccessedVariable // ReSharper disable once UnusedVariable AssociateRM assetManagerRM = (AssociateRM)appService.Handle(createAssetManagerForTPS).Result; // XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX // Set up Associate as predecessor Debug.WriteLine("EFTEST: Set up associate as predecessor"); Commands.V1.Associate.Create createPredecessor = new Commands.V1.Associate.Create { AssociateTypeId = (int)AssociateTypeLookup.AssociateTypeEnum.InternalLDCFacility, DUNSNumber = _dunsNumber++, IsDeactivating = false, IsInternal = true, IsParent = false, LongName = "AGL Services", ShortName = "SCS", StatusCodeId = (int)StatusCodeLookup.StatusCodeEnum.Active }; Debug.WriteLine("EFTEST: Get PredecessorManagerRM for predecessor"); // ReSharper disable once NotAccessedVariable // ReSharper disable once UnusedVariable AssociateRM predecessorManagerRM = (AssociateRM)appService.Handle(createPredecessor).Result; }
public CommandResult SaveUser(UserRM command) { string result = ""; try { //int? userExist = 0; string sqluser = string.Format(@"SELECT TOP 1 CAST(UserId as NVARCHAR(MAX)) as UserId FROM AspNetUsers Where UserName = '******' ", command.objUser.PhoneNumber); var userExist = _unitOfWork.GenericRepositories <AspNetUsers>().FindBy(x => x.UserName == command.objUser.PhoneNumber).FirstOrDefault(); if (userExist == null && command.objUser.UserID == 0) { if (command.objUser.UserID == 0) { string userid = string.Format(@"Select Top 1 Cast(UserId as nvarchar(max)) From AspNetUsers Where len(UserId) <> '5' ORDER BY UserId DESC"); string ipname = string.Format(@"Select Name From ObservationalOrganization Where ID = {0}", command.objUser.Organization); var newuserid = _unitOfWork.RawSqlQuery <string>(userid).FirstOrDefault(); //command.objUser.UserID = Convert.ToInt32(newuserid) + 1; command.objUser.OldPassword = "******"; command.objUser.Id = Guid.NewGuid().ToString(); command.objUser.UserName = command.objUser.PhoneNumber; command.objUser.PasswordHash = Hash(command.objUser.OldPassword); //command.objUser.PasswordHash = "AGFHk67PwvkjEGGoOTToIyMpqzAaWyi0u+duhcnImkR/feAb5pzFBgQLwKAg7U8b0A=="; command.objUser.EmailConfirmed = false; command.objUser.PhoneNumberConfirmed = false; command.objUser.TwoFactorEnabled = false; command.objUser.LockoutEnabled = true; command.objUser.AccessFailedCount = 0; command.objUser.Organization = _unitOfWork.RawSqlQuery <string>(ipname).FirstOrDefault(); command.objUser.LanguageName = "en"; //command.objSuchanaUser.SecurityStamp = new AspNetUsers //{ // PasswordHash = Hash(command.objSuchanaUser.OldPassword), // Email = command.objSuchanaUser.Email, // UserName = command.objSuchanaUser.PhoneNumber, // SecurityStamp = Guid.NewGuid().ToString() //}.ToString(); command.objUser.CreateBy = command.UserId + ""; command.objUser.CreateDate = DateTime.Now; command.objUser.SecurityStamp = "540d247b-b097-4783-81d3-18bbe60e04bc"; _unitOfWork.GenericRepositories <AspNetUsers>().Insert(command.objUser); result = _unitOfWork.SaveChange(); LogEventStore(command.objUser.Id.ToString(), "AspNetUsers", "Save"); } return(new CommandResult() { Status = 400, Message = result != "" ? result : "Record Save successfully." }); } else if (userExist != null && command.objUser.UserID != 0) { string ipname = string.Format(@"Select Name From ObservationalOrganization Where ID = {0}", command.objUser.Organization); var user = _unitOfWork.GenericRepositories <AspNetUsers>().GetAll().Where(x => x.UserID == command.objUser.UserID).FirstOrDefault(); user.FullName = command.objUser.FullName; user.Email = command.objUser.Email; user.PhoneNumber = command.objUser.PhoneNumber; user.UserName = command.objUser.PhoneNumber; user.Organization = _unitOfWork.RawSqlQuery <string>(ipname).FirstOrDefault(); user.Designation = command.objUser.Designation; user.StaffID = command.objUser.StaffID; user.IsActive = command.objUser.IsActive; user.UserType = command.objUser.UserType; user.GeoType = command.objUser.GeoType; user.EditBy = command.UserId + ""; user.EditDate = DateTime.Now; _unitOfWork.GenericRepositories <AspNetUsers>().Update(user); result = _unitOfWork.SaveChange(); LogEventStore(command.objUser.UserID.ToString(), "AspNetUsers", "Update"); return(new CommandResult() { Status = 200, Message = result != "" ? result : "Record Save successfully." }); } else { return(new CommandResult() { Status = 111, Message = result != "" ? result : "User already Exist!" }); } } catch (Exception ex) { throw new Exception(ex.Message); } }