Esempio n. 1
0
        public static ReturnObject Edit(HttpContext context, long id, long parent_id, string username, string password, string email, string first_name, string last_name, string street, string city, string state, string zip, string company = null, string street_2 = null, string phone = null)
        {
            Lib.Data.DrugCompanyUser item = null;
            Lib.Data.DrugCompany parent = new Data.DrugCompany(parent_id);
            Lib.Data.UserProfile profile = null;
            Lib.Data.Contact contact = null;
            Lib.Data.Address address = null;
            Framework.Security.User user = null;

            if (id > 0)
            {
                item = new Lib.Data.DrugCompanyUser(id);
                profile = item.Profile;
                user = profile.User;
                contact = profile.PrimaryContact;
                address = profile.PrimaryAddress;
            }
            else
            {
                item = new Lib.Data.DrugCompanyUser();
                profile = new Data.UserProfile();
                profile.Created = DateTime.Now;
                contact = new Data.Contact();
                address = new Data.Address();

                string error = "";
                user = Framework.Security.Manager.CreateUser(username, password, email, out error);

                user.AddGroup(Framework.Security.Group.FindByName("users"));
                user.AddGroup(Framework.Security.Group.FindByName("drugcompany"));

                if (!string.IsNullOrEmpty(error))
                {
                    return new ReturnObject()
                    {
                        Error = true,
                        StatusCode = 200,
                        Message = error
                    };
                }
            }

            address.Street1 = street;
            address.Street2 = street_2;
            address.City = city;
            address.State = state;
            address.Zip = zip;
            address.Country = "United States";
            address.Save();

            contact.Email = email;
            contact.FirstName = first_name;
            contact.LastName = last_name;
            contact.Phone = phone;
            contact.Save();

            var ut = Lib.Data.UserType.FindByName("drug-company");

            profile.UserTypeID = ut.ID.Value;
            profile.UserID = user.ID.Value;
            profile.PrimaryAddressID = address.ID.Value;
            profile.PrimaryContactID = contact.ID.Value;
            profile.Save();

            item.ProfileID = profile.ID.Value;
            item.DrugCompanyID = parent.ID.Value;
            item.Save();

            return new ReturnObject()
            {
                Result = item,
                Redirect = new ReturnRedirectObject()
                {
                    Hash = "admin/drugs/companies/list"
                },
                Growl = new ReturnGrowlObject()
                {
                    Type = "default",
                    Vars = new ReturnGrowlVarsObject()
                    {
                        text = "You have successfully saved this drug company user.",
                        title = "Drug Company User Saved"
                    }
                }
            };
        }
Esempio n. 2
0
        public static ReturnObject Edit(HttpContext context, long provider_user_id, long organization_id, long facility_id, string user_type, string username, string password, string email, string first_name, string last_name, string street, string city, string state, string zip, string street_2 = null, string phone = null)
        {
            Lib.Data.Provider provider;
            Lib.Data.ProviderUser providerUser;

            UserProfile userProfile;
            Contact contact;
            Address address;

            Framework.Security.User user;

            if (provider_user_id > 0)
            {
                providerUser = new Lib.Data.ProviderUser(provider_user_id);
                provider = providerUser.Provider;
                userProfile = providerUser.Profile;
                user = userProfile.User;
                contact = userProfile.PrimaryContact;
                address = userProfile.PrimaryAddress;

                user.Username = username;
                user.Save();

                Framework.Security.Manager.SetPassword(user, password);
            }
            else
            {
                provider = new Lib.Data.Provider();
                providerUser = new Lib.Data.ProviderUser();
                userProfile = new Data.UserProfile();
                userProfile.Created = DateTime.Now;
                contact = new Data.Contact();
                address = new Data.Address();

                string error = "";
                user = Framework.Security.Manager.CreateUser(username, password, email, out error);

                user.AddGroup(Framework.Security.Group.FindByName("users"));
                user.AddGroup(Framework.Security.Group.FindByName("providers"));

                if (!string.IsNullOrEmpty(error))
                {
                    return new ReturnObject()
                    {
                        Error = true,
                        StatusCode = 200,
                        Message = error
                    };
                }
            }

            if (user_type != "technical" && user_type != "administrative")
            {
                return new ReturnObject()
                {
                    Error = true,
                    StatusCode = 200,
                    Message = "Invalid user type."
                };
            }

            address.Street1 = street;
            address.Street2 = street_2;
            address.City = city;
            address.State = state;
            address.Zip = zip;
            address.Country = "United States";
            address.Save();

            contact.Email = email;
            contact.FirstName = first_name;
            contact.LastName = last_name;
            contact.Phone = phone;
            contact.Save();

            provider.AddressID = address.ID;
            provider.PrimaryContactID = contact.ID;
            provider.Created = DateTime.Now;
            provider.FacilitySize = String.Empty;
            provider.Name = string.Empty;
            provider.Save();

            var ut = Lib.Data.UserType.FindByName("provider");

            userProfile.UserTypeID = ut.ID.Value;
            userProfile.UserID = user.ID.Value;
            userProfile.PrimaryAddressID = address.ID.Value;
            userProfile.PrimaryContactID = contact.ID.Value;
            userProfile.Save();

            providerUser.ProfileID = userProfile.ID.Value;
            providerUser.ProviderID = provider.ID.Value;
            providerUser.OrganizationID = organization_id;
            providerUser.ProviderUserType = user_type;
            providerUser.PrimaryFacilityID = facility_id;
            providerUser.Save();

            return new ReturnObject()
            {
                Result = providerUser,
                Growl = new ReturnGrowlObject()
                {
                    Type = "default",
                    Vars = new ReturnGrowlVarsObject()
                    {
                        text = "You have successfully saved this provider user.",
                        title = "Provider User Saved"
                    }
                }
            };
        }
Esempio n. 3
0
        public static Lib.Data.UserList GetUsersDrugList( long profile_id )
        {
            var profile = new Data.UserProfile( profile_id );

            var lists = Lib.Data.UserList.FindByUserProfile( profile, "drug", true );

            if( lists.Count > 0 )
            {
                for( int i = 0; i < lists.Count; i++ )
                    if( lists[i].Name == "My Drugs" )
                        return lists[i];
            }

            var ret = new Data.UserList();

            ret.DataType = "drug";
            ret.DateCreated = DateTime.Now;
            ret.DateModified = DateTime.Now;
            ret.Name = "My Drugs";
            ret.System = true;
            ret.UserProfileID = profile.ID;
            ret.Save();

            return ret;
        }
Esempio n. 4
0
        public static ReturnObject EditProvider(HttpContext context, long provider_user_id, string username, string password, string email, string first_name, string last_name, string street, string city, string state, string zip, string expires_on, string is_enabled, string street_2 = null, string phone = null)
        {
            IAccountService accountSvc = ObjectFactory.GetInstance<IAccountService>();

            Lib.Data.Provider provider;
            Lib.Data.ProviderUser providerUser;

            UserProfile userProfile;
            Contact contact;
            Address address;
            Account account;

            Framework.Security.User user;

            if (provider_user_id > 0)
            {
                providerUser = new Lib.Data.ProviderUser(provider_user_id);
                provider = providerUser.Provider;
                userProfile = providerUser.Profile;
                user = userProfile.User;
                contact = userProfile.PrimaryContact;
                address = userProfile.PrimaryAddress;

                account = accountSvc.GetByUserProfileId(userProfile.ID ?? 0);

                user.Username = username;
                user.Save();

                Framework.Security.Manager.SetPassword(user, password);
            }
            else
            {
                provider = new Lib.Data.Provider();
                providerUser = new Lib.Data.ProviderUser();
                userProfile = new Data.UserProfile();
                userProfile.Created = DateTime.Now;
                contact = new Data.Contact();
                address = new Data.Address();

                account = new Account
                {
                    CreatedAt = DateTime.Now
                };

                string error = "";
                user = Framework.Security.Manager.CreateUser(username, password, email, out error);

                user.AddGroup(Framework.Security.Group.FindByName("users"));
                user.AddGroup(Framework.Security.Group.FindByName("providers"));

                if (!string.IsNullOrEmpty(error))
                {
                    return new ReturnObject()
                    {
                        Error = true,
                        StatusCode = 200,
                        Message = error
                    };
                }
            }

            DateTime expiresOn;

            if(!DateTime.TryParse(expires_on, out expiresOn))
            {
                    return new ReturnObject()
                    {
                        Error = true,
                        StatusCode = 200,
                        Message = "Invalide expiration date."
                    };
            }

            address.Street1 = street;
            address.Street2 = street_2;
            address.City = city;
            address.State = state;
            address.Zip = zip;
            address.Country = "United States";
            address.Save();

            contact.Email = email;
            contact.FirstName = first_name;
            contact.LastName = last_name;
            contact.Phone = phone;
            contact.Save();

            provider.AddressID = address.ID;
            provider.PrimaryContactID = contact.ID;
            provider.Created = DateTime.Now;
            provider.FacilitySize = String.Empty;
            provider.Name = string.Empty;
            provider.Save();

            var ut = Lib.Data.UserType.FindByName("provider");

            userProfile.UserTypeID = ut.ID.Value;
            userProfile.UserID = user.ID.Value;
            userProfile.PrimaryAddressID = address.ID.Value;
            userProfile.PrimaryContactID = contact.ID.Value;
            userProfile.IsEcommerce = true;
            userProfile.Save();

            providerUser.ProfileID = userProfile.ID.Value;
            providerUser.ProviderID = provider.ID.Value;
            providerUser.OrganizationID = 0;
            providerUser.ProviderUserType = "";
            providerUser.PrimaryFacilityID = 0;
            providerUser.Save();

            account.UserProifleId = userProfile.ID ?? 0;
            account.ExpiresOn = expiresOn;
            account.IsEnabled = is_enabled == "yes";

            accountSvc.Save(account);

            return new ReturnObject()
            {
                Result = providerUser,
                Growl = new ReturnGrowlObject()
                {
                    Type = "default",
                    Vars = new ReturnGrowlVarsObject()
                    {
                        text = "You have successfully saved this provider user.",
                        title = "Provider User Saved"
                    }
                }
            };
        }
Esempio n. 5
0
        public static ReturnObject Edit(HttpContext context, string username, string email, long user_type, string contact_prefix, string contact_name, string contact_phone, string contact_suffix = "", string contact_title = "", string contact_fax = "", string password = "", string confirm = "", long id = 0)
        {
            if( id == 0 && string.IsNullOrEmpty( password ) )
                return new ReturnObject() { Error = true, Message = "A password is required to create a new user." };

            Framework.Security.User item = null;
            Data.UserProfile profile = null;
            Data.Contact contact = null;
            if (id > 0)
            {
                item = new Framework.Security.User(id);
                profile = Data.UserProfile.FindByUser(item);
                contact = profile.PrimaryContact;
                if( contact == null )
                    contact = new Data.Contact();
            }
            else
            {
                if (Framework.Security.Manager.UserExists(email, username))
                    return new ReturnObject() { Error = true, Message = "A user with that username / email is already in the system." };

                item = new Framework.Security.User();
                item.ResetPasswordGuid = Guid.Empty;
                item.LastLogin = DateTime.Now;

                profile = new Data.UserProfile();
                profile.Created = DateTime.Now;
                contact = new Data.Contact();
            }
            item.Username = username;
            item.Email = email;
            if( !string.IsNullOrEmpty( password ) )
            {
                if( password != confirm )
                    return new ReturnObject() { Error = true, Message = "Your passwords do not match." };

                item.PasswordSalt = Framework.Security.Manager.GetRandomSalt();
                item.Password = Framework.Security.Hash.GetSHA512(password+item.PasswordSalt);
            }

            var name_parts = contact_name.Split(' ');

            if (name_parts.Length <= 1)
                return new ReturnObject() { Error = true, Message = "Please enter the contact's full name." };

            item.Save();

            string fname = name_parts[0];
            string lname = name_parts[name_parts.Length - 1];
            for (var i = 1; i < name_parts.Length - 1; i++)
                fname += " " + name_parts[i];

            contact.Prefix = contact_prefix;
            contact.FirstName = fname;
            contact.LastName = lname;
            contact.Postfix = contact_suffix;
            contact.Title = contact_title;
            contact.Email = email;
            contact.Phone = contact_phone;
            contact.Fax = contact_fax;
            contact.Save();

            profile.UserID = item.ID.Value;
            if (profile.UserTypeID != user_type)
            {
                profile.UserTypeID = user_type;

                item.ClearGroups();

                item.AddGroup(Framework.Security.Group.FindByName("users"));
                item.AddGroup(Framework.Security.Group.FindByName("admin"));

                if( user_type == 1 )
                    item.AddGroup(Framework.Security.Group.FindByName("dev"));
            }
            profile.PrimaryContactID = contact.ID;
            profile.Save();

            return new ReturnObject() { Result = item, Redirect = new ReturnRedirectObject() { Hash = "admin/security/users/list" }, Growl = new ReturnGrowlObject() { Type = "default", Vars = new ReturnGrowlVarsObject() { text = "You have successfully saved this user.", title = "User Saved" } } };
        }