Beispiel #1
0
        public string AddComp(RequestObject req)
        {
            string status = "";

            status += req.comp;
            MyUserModel userModel = new MyUserModel();

            MyUser myUser = new MyUser();

            myUser = userModel.GetUserByName(req.username);

            CompanyModel compModel = new CompanyModel();

            Company c = CreateCompany(req.comp);

            if (myUser != null)
            {
                Company test         = compModel.GetCompanyByName(req.comp);
                string  currentComps = myUser.Companies;
                if (currentComps == "" || currentComps == null)
                {
                    currentComps += req.comp;
                }
                else if (!currentComps.Contains(req.comp))
                {
                    currentComps += "," + req.comp;
                }
                if (test != null)
                {
                    UpdateCompanies(myUser, currentComps);
                    status = "Success";
                }
                else
                {
                    UpdateCompanies(myUser, currentComps);
                    string wasAdded = compModel.InsertCompany(c);
                    status = "Success";
                }
            }
            return(status);
        }
        protected void btnAdd_Click(object sender, EventArgs e)
        {
            var user = Context.User.Identity;

            MyUserModel userModel = new MyUserModel();

            MyUser myUser = new MyUser();

            myUser = userModel.GetUserByName(user.Name);

            CompanyModel compModel = new CompanyModel();

            Company c = CreateCompany();

            if (myUser != null)
            {
                Company test         = compModel.GetCompanyByName(txtComp.Text);
                string  currentComps = myUser.Companies;
                if (currentComps == "" || currentComps == null)
                {
                    currentComps += txtComp.Text;
                }
                else if (!currentComps.Contains(txtComp.Text))
                {
                    currentComps += "," + txtComp.Text;
                }
                if (test != null)
                {
                    UpdateCompanies(myUser, currentComps);
                    litStatus.Text = txtComp.Text + " was successfully added.";
                }
                else
                {
                    UpdateCompanies(myUser, currentComps);
                    string wasAdded = compModel.InsertCompany(c);
                    litStatus.Text = txtComp.Text + " was successfully added.";
                }
            }
        }