/// <summary> /// Creates a phone number /// </summary> /// <param name="phoneModel"></param> /// <returns></returns> public int Create(PhoneModel phoneModel) { using (var scope = new TransactionScope()) { var phone = new PhoneNumber() { AreaCode = phoneModel.AreaCode, Created = DateTime.Now, CreatedBy = phoneModel.CreatedBy, LastModified = DateTime.Now, LastModifiedBy = phoneModel.LastModifiedBy, Extension = phoneModel.Extension, Number = phoneModel.PhoneNumber, PhoneTypeId = phoneModel.PhoneTypeId, Archived = phoneModel.Archived }; var phoneCheck = _dbActions.PhoneNumberRepository.GetSingle(p => p.AreaCode == phoneModel.AreaCode && p.Number == phoneModel.PhoneNumber && p.Extension == phoneModel.Extension); if (phoneCheck == null) { _dbActions.PhoneNumberRepository.Insert(phone); _dbActions.Save(); scope.Complete(); return(phone.Id); } scope.Complete(); return(-1); } }
/// <summary> /// Creates a user security /// </summary> /// <param name="userSecurityModel"></param> /// <returns></returns> public int Create(UserSecurityModel userSecurityModel) { using (var scope = new TransactionScope()) { var userSecurity = new UserSecurity() { UserId = userSecurityModel.Id, IpAddress = userSecurityModel.IpAddress, LockedOut = userSecurityModel.IsLockedOut, Password = userSecurityModel.Password, Created = userSecurityModel.Created, CreatedBy = userSecurityModel.CreatedBy, LastModified = userSecurityModel.LastModified, LastModifiedBy = userSecurityModel.LastModifiedBy, }; var userCheck = _dbActions.UserSecurityRepository.GetSingle(p => p.UserId == userSecurityModel.UserId || p.IpAddress == userSecurityModel.IpAddress); if (userCheck == null) { _dbActions.UserSecurityRepository.Insert(userSecurity); _dbActions.Save(); scope.Complete(); return(userSecurity.Id); } scope.Complete(); return(-1); } }
/// <summary> /// Creates a lookup type /// </summary> /// <param name="addressModel"></param> /// <returns></returns> public int Create(AddressModel addressModel) { using (var scope = new TransactionScope()) { var address = new Address() { Address1 = addressModel.Address1, Address2 = addressModel.Address2, City = addressModel.City, StateId = addressModel.State.Id, Zip = addressModel.Zip, AddressTypeId = addressModel.AddressType.Id, Created = addressModel.Created, CreatedBy = addressModel.CreatedBy, LastModified = addressModel.LastModified, LastModifiedBy = addressModel.LastModifiedBy, Archived = addressModel.Archived }; var addressCheck = _dbActions.AddressRepository.GetSingle(p => p.Address1 == addressModel.Address1 && p.Address2 == addressModel.Address2 && p.City == addressModel.City && p.StateId == addressModel.StateId && p.Zip == addressModel.Zip); if (addressCheck == null) { _dbActions.AddressRepository.Insert(address); _dbActions.Save(); scope.Complete(); return(address.Id); } scope.Complete(); return(-1); } }
public bool UpdateLoginStatus(int userId, string jwToken, DateTime tokenExpiration) { try { var loginStatus = _dbActions.LoginStatusRepository.GetSingle(p => p.UserId == userId); if (loginStatus != null) { using (var scope = new TransactionScope()) { loginStatus.Id = loginStatus.Id; loginStatus.UserId = userId; loginStatus.JwToken = jwToken; loginStatus.TokenExpires = tokenExpiration; loginStatus.CreatedBy = loginStatus.CreatedBy; loginStatus.Created = loginStatus.Created; loginStatus.LastModified = DateTime.Now; loginStatus.LastModifiedBy = "SYSTEM"; _dbActions.LoginStatusRepository.Update(loginStatus); _dbActions.Save(); scope.Complete(); return(true); } } using (var scope = new TransactionScope()) { LoginStatus newLoginStatus = new LoginStatus { UserId = userId, JwToken = jwToken, TokenExpires = tokenExpiration, CreatedBy = "SYSTEM", Created = DateTime.Now, LastModified = DateTime.Now, LastModifiedBy = "SYSTEM" }; _dbActions.LoginStatusRepository.Insert(newLoginStatus); _dbActions.Save(); scope.Complete(); return(true); } } catch (Exception e) { Debug.WriteLine(e.Message); throw; } }
/// <summary> /// Creates a state /// </summary> /// <param name="stateModel"></param> /// <returns></returns> public int Create(StateModel stateModel) { using (var scope = new TransactionScope()) { var state = new StateLookup() { StateName = stateModel.StateName, StateAbbreviation = stateModel.StateAbbreviation, Archived = stateModel.Archived }; _dbActions.StateRepository.Insert(state); _dbActions.Save(); scope.Complete(); return(state.Id); } }
/// <summary> /// Creates a address type /// </summary> /// <param name="addressTypeModel"></param> /// <returns></returns> public int Create(AddressTypeModel addressTypeModel) { using (var scope = new TransactionScope()) { var addressType = new AddressTypeLookup() { AddressType = addressTypeModel.AddressType, Archived = addressTypeModel.Archived }; var addressTypeCheck = _dbActions.AddressTypeRepository.GetSingle(p => p.AddressType == addressTypeModel.AddressType); if (addressTypeCheck == null) { _dbActions.AddressTypeRepository.Insert(addressType); _dbActions.Save(); scope.Complete(); return(addressType.Id); } scope.Complete(); return(-1); } }
/// <summary> /// Creates a user /// </summary> /// <param name="userRoleModel"></param> /// <returns></returns> public int Create(RoleModel userRoleModel) { using (var scope = new TransactionScope()) { var userRole = new Role() { RoleName = userRoleModel.Name, Description = userRoleModel.Description, Created = userRoleModel.Created, CreatedBy = userRoleModel.CreatedBy, LastModified = userRoleModel.LastModified, LastModifiedBy = userRoleModel.LastModifiedBy, Archived = userRoleModel.Archived, //Users = userRoleModel.AssignedUsers.Select(p => new User() //{ // Id = p.Id, // UserName = p.UserName, // EmailAddress = p.EmailAddress, // Created = p.Created, // CreatedBy = p.CreatedBy, // LastModified = p.LastModified, // LastModifiedBy = p.LastModifiedBy, // Archived = p.Archived, //}).ToList() }; var userRoleCheck = _dbActions.UserRoleRepository.GetSingle(p => p.RoleName == userRoleModel.Name); if (userRoleCheck == null) { _dbActions.UserRoleRepository.Insert(userRole); _dbActions.Save(); scope.Complete(); return(userRole.Id); } scope.Complete(); return(-1); } }
/// <summary> /// Creates a address type /// </summary> /// <param name="phoneTypeModel"></param> /// <returns></returns> public int Create(PhoneTypeModel phoneTypeModel) { using (var scope = new TransactionScope()) { var phoneType = new PhoneTypeLookup() { PhoneType = phoneTypeModel.PhoneType, Archived = phoneTypeModel.Archived }; var phoneTypeCheck = _dbActions.PhoneTypeRepository.GetSingle(p => p.PhoneType == phoneTypeModel.PhoneType); if (phoneTypeCheck == null) { _dbActions.PhoneTypeRepository.Insert(phoneType); _dbActions.Save(); scope.Complete(); return(phoneType.Id); } scope.Complete(); return(-1); } }
/// <summary> /// Creates a user /// </summary> /// <param name="userModel"></param> /// <returns></returns> public int Create(UserModel userModel) { using (var scope = new TransactionScope()) { var user = new User() { UserName = userModel.UserName, EmailAddress = userModel.EmailAddress, ContactId = userModel.ContactId, Roles = userModel.Roles.Select(p => new Role() { Id = p.Id, RoleName = p.Name, Description = p.Description, CreatedBy = p.CreatedBy, Created = p.Created, LastModified = p.LastModified, LastModifiedBy = p.LastModifiedBy, Archived = p.Archived }).ToList(), Created = userModel.Created, CreatedBy = userModel.CreatedBy, LastModified = userModel.LastModified, LastModifiedBy = userModel.LastModifiedBy, Archived = userModel.Archived }; var userCheck = _dbActions.UserRepository.GetSingle(p => p.UserName == userModel.UserName || p.EmailAddress == userModel.EmailAddress); if (userCheck == null) { _dbActions.UserRepository.Insert(user); _dbActions.Save(); scope.Complete(); return(user.Id); } scope.Complete(); return(-1); } }
/// <summary> /// Creates a Customer /// </summary> /// <param name="customerModel"></param> /// <returns></returns> public int Create(CustomerModel customerModel) { using (var scope = new TransactionScope()) { var customer = new Customer() { AccountNumber = customerModel.AccountNumber, AccountRepId = customerModel.AccountRep.Id, AccountRep = new Contact() { Id = customerModel.AccountRep.Id, EmailAddress = customerModel.AccountRep.EmailAddress, FirstName = customerModel.AccountRep.FirstName, LastName = customerModel.AccountRep.LastName, Created = customerModel.AccountRep.Created, CreatedBy = customerModel.AccountRep.CreatedBy, LastModified = customerModel.AccountRep.LastModified, LastModifiedBy = customerModel.AccountRep.LastModifiedBy }, IsParentInd = customerModel.IsParent, ParentId = customerModel.ParentId, //Cannot insert parent through child!!!!! Name = customerModel.Name, ShipToBillInd = customerModel.ShipToBill, WebsiteUrl = customerModel.WebsiteUrl, Addresses = customerModel.Addresses?.Select(p => new Address() { Id = p.Id, AddressTypeId = p.AddressType.Id, Address1 = p.Address1, Address2 = p.Address2, City = p.City, StateId = p.State.Id, Zip = p.Zip, Created = p.Created, CreatedBy = p.CreatedBy, LastModified = p.LastModified, LastModifiedBy = p.LastModifiedBy, Archived = p.Archived }).ToList(), PhoneNumbers = customerModel.PhoneNumbers?.Select(p => new PhoneNumber() { Id = p.Id, AreaCode = p.AreaCode, PhoneTypeId = p.PhoneTypeId, Number = p.PhoneNumber, Extension = p.Extension, Created = p.Created, CreatedBy = p.CreatedBy, LastModified = p.LastModified, LastModifiedBy = p.LastModifiedBy }).ToList(), Contacts = customerModel.Contacts.Select(p => new Contact() { Id = p.Id, EmailAddress = p.EmailAddress, FirstName = p.FirstName, LastName = p.LastName, Created = p.Created, CreatedBy = p.CreatedBy, LastModified = p.LastModified, LastModifiedBy = p.LastModifiedBy }).ToList(), Created = DateTime.Now, CreatedBy = customerModel.CreatedBy, LastModified = DateTime.Now, LastModifiedBy = customerModel.LastModifiedBy, Archived = customerModel.Archived }; if (customer.Addresses != null) { foreach (Address addr in customer.Addresses) { _dbActions.Context.Entry(addr).State = addr.Id == 0 ? EntityState.Added : EntityState.Unchanged; } } if (customer.PhoneNumbers != null) { foreach (PhoneNumber phone in customer.PhoneNumbers) { _dbActions.Context.Entry(phone).State = phone.Id == 0 ? EntityState.Added : EntityState.Unchanged; } } var customerCheck = _dbActions.CustomerRepository.GetSingle(p => p.Name == customer.Name); if (customerCheck == null) { _dbActions.CustomerRepository.Insert(customer); _dbActions.Save(); scope.Complete(); return(customer.Id); } scope.Complete(); return(-1); } }
/// <summary> /// Creates a contact /// </summary> /// <param name="contactModel"></param> /// <returns></returns> public int Create(ContactModel contactModel) { using (var scope = new TransactionScope()) { var contact = new Contact() { FirstName = contactModel.FirstName, LastName = contactModel.LastName, EmailAddress = contactModel.EmailAddress, Addresses = contactModel.Addresses?.Select(p => new Address() { Id = p.Id, AddressTypeId = p.AddressType.Id, Address1 = p.Address1, Address2 = p.Address2, City = p.City, StateId = p.State.Id, Zip = p.Zip, Created = p.Created, CreatedBy = p.CreatedBy, LastModified = p.LastModified, LastModifiedBy = p.LastModifiedBy, Archived = p.Archived }).ToList(), PhoneNumbers = contactModel.PhoneNumbers?.Select(p => new PhoneNumber() { Id = p.Id, AreaCode = p.AreaCode, PhoneTypeId = p.PhoneTypeId, Number = p.PhoneNumber, Extension = p.Extension, Created = p.Created, CreatedBy = p.CreatedBy, LastModified = p.LastModified, LastModifiedBy = p.LastModifiedBy }).ToList(), Created = DateTime.Now, CreatedBy = contactModel.CreatedBy, LastModified = DateTime.Now, LastModifiedBy = contactModel.LastModifiedBy, Archived = contactModel.Archived }; if (contact.Addresses != null) { foreach (Address addr in contact.Addresses) { _dbActions.Context.Entry(addr).State = addr.Id == 0 ? EntityState.Added : EntityState.Unchanged; } } if (contact.PhoneNumbers != null) { foreach (PhoneNumber phone in contact.PhoneNumbers) { _dbActions.Context.Entry(phone).State = phone.Id == 0 ? EntityState.Added : EntityState.Unchanged; } } var contactCheck = _dbActions.ContactRepository.GetSingle(p => p.EmailAddress == contact.EmailAddress); if (contactCheck == null) { _dbActions.ContactRepository.Insert(contact); _dbActions.Save(); scope.Complete(); return(contact.Id); } scope.Complete(); return(-1); } }