Beispiel #1
0
        /// <summary>
        /// Filter through Tops
        /// </summary>
        /// <param name="designer"></param>
        /// <param name="neck"></param>
        /// <param name="sleeve"></param>
        /// <param name="chest"></param>
        /// <returns>top already exists</returns>
        private DataBaseResults DoesTopExistInDB(int designer, int neck, int sleeve, int chest)
        {
            DataBaseResults doesTopExist = new DataBaseResults();

            foreach (Top top in Tops)
            {
                if (top.IsMatch(designer, neck, sleeve, chest))
                {
                    doesTopExist.ItemIDExists = true;
                    doesTopExist.ID           = top.ID;
                    break;
                }
            }

            return(doesTopExist);
        }
Beispiel #2
0
        /// <summary>
        /// We'll try updating the DB and also try creating a new Top item
        /// </summary>
        /// <param name="designer"></param>
        /// <param name="neck"></param>
        /// <param name="sleeve"></param>
        /// <param name="chest"></param>
        internal DataBaseResults Create(string designer, string neck, string sleeve, string chest, int UserID)
        {
            DataBaseResults userContributedToDataBase = new DataBaseResults();

            DataBaseResults designerID = DataBase.TryUpdatingTables(DesignerDict, TABLE_DESIGNER, COLUMN_NAME, designer);
            DataBaseResults neckID     = DataBase.TryUpdatingTables(NeckDict, TABLE_NECK, COLUMN_SIZE, neck);
            DataBaseResults sleeveID   = DataBase.TryUpdatingTables(SleeveDict, TABLE_SLEEVE, COLUMN_SIZE, sleeve);
            DataBaseResults chestID    = DataBase.TryUpdatingTables(ChestDict, TABLE_CHEST, COLUMN_SIZE, chest);

            //Did the user contribute to the dataBase?
            if (designerID.NewItemAdded ||
                neckID.NewItemAdded ||
                sleeveID.NewItemAdded ||
                chestID.NewItemAdded)
            {
                userContributedToDataBase.NewItemAdded = true;
            }
            Top top = new Top(0, designerID.ID, neckID.ID, chestID.ID, sleeveID.ID, 0);

            userContributedToDataBase = DoesTopExistInDB(top);

            //If item doesn't exist lets try to add it
            if (!userContributedToDataBase.ItemIDExists)
            {
                string[] columns = { TABLE_TOP_COLUMN_DESIGNER, TABLE_TOP_COLUMN_NECK, TABLE_TOP_COLUMN_SLEEVE, TABLE_TOP_COLUMN_CHEST, TABLE_TOP_COLUMN_CREATEDBYUSER, TABLE_TOP_COLUMN_VALIDATED };
                string[] values  = { designerID.ID.ToString(), neckID.ID.ToString(), sleeveID.ID.ToString(), chestID.ID.ToString(), UserID.ToString(), "0" };

                try
                {
                    userContributedToDataBase = DataBase.CreateNewRow(TABLE_TOP, columns, values);
                    top.ID = userContributedToDataBase.ID;
                    Tops.Add(top);
                }
                catch
                {
                    //If create New Row throws its exception it means that this are now more than 1 tops by this designer
                }
            }

            return(userContributedToDataBase);
        }
Beispiel #3
0
        /// <summary>
        /// User will be added to the database and if it is succesfful we will report that user was added
        /// </summary>
        /// <param name="firstName"></param>
        /// <param name="lastName"></param>
        /// <param name="email"></param>
        /// <param name="p"></param>
        /// <returns></returns>
        private DataBaseResults CreateNewUser(string firstName, string lastName, string email, Int64 p)
        {
            DataBaseResults isNewUser = new DataBaseResults();

            string json = JsonConvert.SerializeObject(CurrentUser);

            string[] columns = { TABLE_USER_COLUMN_EMAIL, TABLE_USER_COLUMN_HASHPASS };
            string[] values  = { email, p.ToString() };

            isNewUser = DataBase.CreateNewRow(TABLE_USER, columns, values);

            //User contributed a new top to the database!
            if (isNewUser.NewItemAdded)
            {
                EmailDict.Add(isNewUser.ID, email);
                CurrentUser = new User(isNewUser.ID, firstName, lastName, email, p);
                UpdateUserProfile(CurrentUser);
            }

            return(isNewUser);
        }
Beispiel #4
0
        protected void btnAddItem_Click(object sender, EventArgs e)
        {
            string designerName = tbDesignerName.Text;
            string neckSize     = tbNeckSize.Text;
            string sleeveSize   = tbSleeveSize.Text;
            string chestSize    = tbChestSize.Text;

            //Determins if we try to add a shirt or not
            Boolean illegalArgument = false;

            if (String.IsNullOrEmpty(designerName))
            {
                illegalArgument = true;
                lblInvalidDesignerName.Visible = true;
            }

            if (String.IsNullOrEmpty(neckSize))
            {
                illegalArgument            = true;
                lblInvalidNeckSize.Visible = true;
            }

            if (String.IsNullOrEmpty(sleeveSize))
            {
                illegalArgument = true;
                lblInvalidSleeveSize.Visible = true;
            }

            if (String.IsNullOrEmpty(chestSize))
            {
                //illegalArgument = true;
                //lblInvalidChestSize.Visible = true;
            }

            if (!illegalArgument)
            {
                //Make sure the inputs are correct
                DataBaseResults result = Top.Create(tbDesignerName.Text, tbNeckSize.Text, tbSleeveSize.Text, tbChestSize.Text, user.ID);

                if (result.ItemIDExists)
                {
                    //TODO the next to lines should be placed in stage 4 of clothes model rating
                    UserRatedClothes item = new UserRatedClothes(Clothes.Type.Top, result.ID, 0);

                    //We have to add the item to the users closet to ensure that our Top DB and User validation stay in sync
                    if (UserModel.TryAddingClosetItem(user, item))
                    {
                        //newly added
                        Top.ValidatedClosetItem(item.ID);
                    }
                    else
                    {
                        //user already owns the item
                        item = user.GetClosetItemById(item.ID);
                    }

                    Session[Constants.Session_CurrentUserRatedItem] = item;
                    Response.Redirect(Constants.Page_RateItem);
                }
                else
                {
                    lblTroubleAddingItem.Visible = true;
                }
            }
        }