コード例 #1
0
 /// <summary>
 /// Deprecated Method for adding a new object to the Companies EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToCompanies(Company company)
 {
     base.AddObject("Companies", company);
 }
コード例 #2
0
        protected void btnSave_Click(object sender, ImageClickEventArgs e)
        {
            SelectedTabElement = 1;
            if (LoggedIsUser == null)//means its sign-up process
            {

                if (ValidateFields() && !companyNameAlreadyExists())
                {
                    User user = new User
                    {
                        ReceiveEmails = checkbox.Checked,
                        FullName = GetFullName(),
                        Surname = surname.Text,
                        Forename = firstname.Text,
                        JobTitle = jobtitle.Text,
                        Email = emailfield.Text,
                        Password = Utility.GetMd5Sum(passwordfield.Text),
                        ReminderQuestionID = byte.Parse(listForgotPasswordQuestion.SelectedValue),
                        ReminderQuestion = listForgotPasswordQuestion.SelectedItem.Text,
                        ReminderAnswer = Utility.GetMd5Sum(txtForgotPasswordAnswer.Text),
                        CreationDate = DateTime.Now,
                        LastAmendmentDate = DateTime.Now,
                        Type = Enum.GetName(typeof(Enums.ENTITY_TYPE), Enums.ENTITY_TYPE.COMPANY_ADMIN),
                        Deleted = false,
                        OnHold = false,
                        Verified = false,
                        Enabled = true,
                        UserUID = Guid.NewGuid().ToString(),
                        VerificationCode = Guid.NewGuid().ToString(),
                        Approved = 0,
                        PaymentType = 0,
                        LoginAttempts = 0
                    };

                    Address address = fillAddress(user, Enums.ADDRESS_TYPE.PERSONAL);
                    Address companyAddress = fillAddress(user, Enums.ADDRESS_TYPE.COMPANY);
                    user.Addresses.Add(address);
                    user.Addresses.Add(companyAddress);

                    Simplicity.Data.Company company = new Simplicity.Data.Company();
                    company.Name = companyname.Text;
                    company.Address = companyAddress;
                    DatabaseContext.AddToCompanies(company);
                    DatabaseContext.SaveChanges();

                    user.CompanyID = company.CompanyID;
                    DatabaseContext.SaveChanges();

                    //call health and safety stored procedure over here to insert company there as well
                    addCompanyToHS(user);
                    EmailUtility.SendAccountCreationEmail(user, passwordfield.Text);
                    Response.Redirect("~/ConfirmMail.aspx");
                }
            }
            else
            {
                if (companyNameAlreadyExists())
                {
                    return;
                }
                bool newCompanyAdded = false;
                User user = (from c in DatabaseContext.Users where c.UserID == LoggedIsUser.UserID select c).FirstOrDefault();

                user.FullName = GetFullName();
                user.Surname = surname.Text;
                user.Forename = firstname.Text;
                user.JobTitle = jobtitle.Text;
                if (user.Company == null)//it means i am an old user and i dont have any company attached yet
                {
                    Simplicity.Data.Company company = new Simplicity.Data.Company();
                    company.Name = companyname.Text;
                    Address companyAddr = fillAddress(user, Enums.ADDRESS_TYPE.COMPANY);
                    company.Address = companyAddr;
                    user.Company = company;
                    newCompanyAdded = true;
                }
                user.Company.Name = companyname.Text;
                user.LastAmendmentDate = DateTime.Now;

                foreach (Address address in user.Addresses)
                {
                    if (address.MultiAddressType == "PERSONAL")
                    {
                        address.AddressFull = GetFullAddress();
                        address.AddressNo = addressno.Text;
                        address.AddressLine1 = addressline1.Text;
                        address.AddressLine2 = addressline2.Text;
                        address.AddressLine3 = addressline3.Text;
                        address.AddressLine4 = addressline4.Text;
                        address.AddressLine5 = addressline5.Text;
                        address.PostalCode = postalcode.Text;
                        address.Telephone1 = telephone1.Text;
                        address.Telephone2 = telephone2.Text;
                        address.Fax = fax.Text;
                        address.Mobile = mobile.Text;
                        address.Town = town.Text;
                        address.County = County.Text;
                        address.Country = country.Text;
                        address.LastAmendmentDate = DateTime.Now;
                        address.AddressName = null;
                        address.LastAmendedBy = null;
                    }
                }
                DatabaseContext.SaveChanges();
                SetSuccessMessage("Save information successfully.");
                if (newCompanyAdded) addCompanyToHS(user);
            }
        }
コード例 #3
0
 /// <summary>
 /// Create a new Company object.
 /// </summary>
 /// <param name="companyID">Initial value of the CompanyID property.</param>
 /// <param name="name">Initial value of the Name property.</param>
 /// <param name="addressID">Initial value of the AddressID property.</param>
 public static Company CreateCompany(global::System.Int32 companyID, global::System.String name, global::System.Int32 addressID)
 {
     Company company = new Company();
     company.CompanyID = companyID;
     company.Name = name;
     company.AddressID = addressID;
     return company;
 }
コード例 #4
0
        protected void AddCompanyAdmin_Click(object source, EventArgs e)
        {
            if (ValidateFields())
            {
                String CompanyType = Enum.GetName(typeof(Enums.ENTITY_TYPE), Enums.ENTITY_TYPE.USER);
                if (!companyNameAlreadyExistsUsingName())
                {
                    CompanyType = Enum.GetName(typeof(Enums.ENTITY_TYPE), Enums.ENTITY_TYPE.COMPANY_ADMIN);
                    User user = new User
                    {
                        ReceiveEmails = checkbox.Checked,
                        FullName = GetFullName(),
                        Surname = surname.Text,
                        Forename = firstname.Text,
                        JobTitle = jobtitle.Text,
                        Email = emailfield.Text,
                        Password = Utility.GetMd5Sum(passwordfield.Text),
                        ReminderQuestionID = byte.Parse(listForgotPasswordQuestion.SelectedValue),
                        ReminderQuestion = listForgotPasswordQuestion.SelectedItem.Text,
                        ReminderAnswer = Utility.GetMd5Sum(txtForgotPasswordAnswer.Text),
                        CreationDate = DateTime.Now,
                        LastAmendmentDate = DateTime.Now,
                        Type = CompanyType,
                        Deleted = false,
                        OnHold = false,
                        Verified = true,
                        Enabled = true,
                        UserUID = Guid.NewGuid().ToString(),
                        VerificationCode = Guid.NewGuid().ToString(),
                        Approved = 0,
                        PaymentType = 0,
                        LoginAttempts = 0
                    };

                    Address address = fillAddressUser(user, Enums.ADDRESS_TYPE.PERSONAL);
                    Address companyAddress = fillAddressUser(user, Enums.ADDRESS_TYPE.COMPANY);
                    user.Addresses.Add(address);
                    user.Addresses.Add(companyAddress);
                    //Simplicity.Data.Company company = (from c in DatabaseContext.Companies where c.Name == companyname.Text select c).FirstOrDefault();
                    Simplicity.Data.Company company = new Simplicity.Data.Company();
                    company.Name = CompanyTabCompanyName.Text;
                    company.Address = companyAddress;
                    DatabaseContext.AddToCompanies(company);
                    DatabaseContext.SaveChanges();

                    user.CompanyID = company.CompanyID;
                    //DatabaseContext.Users.AddObject(user);
                    DatabaseContext.SaveChanges();

                    //call health and safety stored procedure over here to insert company there as well
                    DatabaseUtility.addCompanyToHS(user);
            //                    EmailUtility.SendAccountCreationEmail(user, passwordfield.Text);
                    SetSuccessMessage("Company added successfully.");
                    Response.Redirect("~/Admin/ManageCompanies.aspx");
                }
            }
        }
コード例 #5
0
        private void deleteCompanyRow(int companyId)
        {
            if (companyId >= 0)
            {
                this.company = (from c in DatabaseContext.Companies where c.CompanyID == companyId select c).FirstOrDefault();//select company
                this.company.Address.Deleted = true;//delete address
                IEnumerable<Simplicity.Data.CompanyProduct> products = from cp in DatabaseContext.CompanyProducts where cp.CompanyID == companyId select cp;
                foreach (CompanyProduct product in products)
                {
                    DatabaseContext.CompanyProducts.DeleteObject(product);
                }//delete all company products.

                IEnumerable<User> users = from usrs in DatabaseContext.Users where usrs.CompanyID == companyId select usrs;
                foreach (User usr in users)
                {
                    usr.CompanyID = null;
                    usr.Deleted = true;
                }//delete users belong to the company also set company id to null so that foriegn key constraint allows company to be deleted.

                DatabaseContext.Companies.DeleteObject(this.company);
                DatabaseContext.SaveChanges();
                if (SearchTextBox.Text.ToString().CompareTo("") != 0)
                {
                    this.SetWhereClause();
                }
                else
                {
                    //SimplicityDataSource.AutoGenerateWhereClause = false;
                    UserGrid.DataBind();
                }
            }
        }
コード例 #6
0
 private bool companyNameAlreadyExistsUsingName()
 {
     Simplicity.Data.Company company = null;
     company = (from c in DatabaseContext.Companies where c.Name == CompanyTabCompanyName.Text select c).FirstOrDefault();
     if (company != null)
     {
         if (company.Users != null && company.Users.Count > 0)
             SetErrorMessage("Company already exist. Please Contact " + company.Users.FirstOrDefault().Email);
         else
             SetErrorMessage("Company already exist");
         return true;
     }
     else return false;
 }
コード例 #7
0
        protected void Page_Load(object sender, EventArgs e)
        {
            String strCompId = Request["companyId"];
            if (strCompId != null && strCompId.CompareTo("") != 0){
                int id = Int32.Parse(strCompId);
                this.company = (from c in DatabaseContext.Companies where c.CompanyID == id select c).FirstOrDefault();
            }

            if (!IsPostBack)
            {
                ContentPlaceHolder myContent = (ContentPlaceHolder)this.Master.FindControl("BodyContentPlaceHolder");
                HtmlGenericControl gridBoxDiv = (HtmlGenericControl)myContent.FindControl("GridDiv");
                HtmlGenericControl editCompanyDiv = (HtmlGenericControl)myContent.FindControl("EditCompanyDetailsDiv");

                if (company != null) {
                    gridBoxDiv.Visible = false;
                    editCompanyDiv.Visible = true;

                    companyname.Text = company.Name;
                    addressno.Text = company.Address.AddressNo;
                    addressline1.Text = company.Address.AddressLine1;
                    addressline2.Text = company.Address.AddressLine2;
                    addressline3.Text = company.Address.AddressLine3;
                    addressline4.Text = company.Address.AddressLine4;
                    addressline5.Text = company.Address.AddressLine5;
                    postalcode.Text = company.Address.PostalCode;
                    town.Text = company.Address.Town;
                    County.Text = company.Address.County;
                    country.Text = company.Address.Country;
                    telephone1.Text = company.Address.Telephone1;
                    telephone2.Text = company.Address.Telephone2;
                    fax.Text = company.Address.Fax;
                    mobile.Text = company.Address.Mobile;
                }
                else {
                    gridBoxDiv.Visible = true;
                    editCompanyDiv.Visible = false;
                }
            }
            SimplicityDataSource.Where = "";
            if (SearchTextBox.Text.ToString().CompareTo("") != 0)
            {
                this.searchCompanies();
            }
        }