Ejemplo n.º 1
0
        protected void createCoupon_Click(object sender, EventArgs e)
        {
            //Create Coupon according to its type
            Coupon newCoupon = new Coupon();
            CouponFactory.CouponFactory cf = new CouponFactory.CouponFactory();
            string type = couponType_dropDownList.SelectedValue;
            /*
            if (type.Equals("Social Network"))
                newCoupon = cf.makeNewCoupon(type);
            else
                newCoupon = cf.makeNewCoupon("Regular");
             */

            //Retreive other information and save it in the database

            int disPrice = Int32.Parse(dis_price.Text);
            newCoupon.DiscountPrice = disPrice;
            int orgPrice = Int32.Parse(org_price.Text);
            newCoupon.OriginalPrice = orgPrice;
            string desc = description.Text;
            newCoupon.Description = desc;
            //category
            int categoryid = Int32.Parse(category_dropDownList.SelectedValue);
            newCoupon.CategoryID = categoryid;
            string name = name_txt.Text;
            newCoupon.Name = name;
            int busID = Int32.Parse(business_dropDownList.SelectedValue);
            DateTime lastUse = DateTime.Parse(last_Use.Text);
            newCoupon.LastUseDate = lastUse;
            couponsEntities ce = new couponsEntities();
            newCoupon.BusinessID = busID;
            ce.Coupons.Add(newCoupon);
            ce.SaveChanges();
        }
Ejemplo n.º 2
0
        protected void btn_logIn_Click(object sender, EventArgs e)
        {
            string user = UserName.Text;
            string pass = Password.Text;
            //Regular Way:

            couponsEntities ce = new couponsEntities();
            List<User> lst = ce.Users.ToList();
            foreach (User c in lst)
            {
                if (c.UserName.Equals(user))
                {
                    if (c.Password.Equals(pass))
                    {

                        HttpCookie cookie = Request.Cookies["CouponCookie"];
                        if (cookie == null)
                        {
                            cookie = new HttpCookie("CouponCookie");
                            cookie.Expires = DateTime.Now.AddYears(3);
                            cookie.Values.Add("UserName", c.UserName);
                            cookie.Values.Add("LastEntered", DateTime.Now.ToString());
                            cookie.Values.Add("UserType", c.UserType.ToString());
                        }
                        else
                        {
                            cookie["UserName"] = c.UserName;
                            cookie["LastEntered"] = DateTime.Now.ToString();
                            cookie["UserType"] = c.UserType.ToString();
                        }
                        Response.Cookies.Add(cookie);

                        //Set Session Current User
                        Session["CurrentUserName"] = user;
                        Session["LastEntered"] = DateTime.Now.ToString();
                        Session["CurrentUserType"] = c.UserType.ToString();

                        //Check If admin

                        if ((int)c.UserType == 1)//Move to Admin HomePage
                        {
                            Response.Redirect("~/AdminHomePage.aspx");
                        }
                        else if ((int)c.UserType == 3) // business manager
                        {
                            Response.Redirect("~/BusinessManagerHomePage.aspx");
                        }
                        else //Regular User
                        {
                            string to = "HomePage.aspx?userName="******"Username or password incorrect";
            lbl_wrongDetails.Visible = true;
        }
Ejemplo n.º 3
0
        public List<Coupon> findCoupons()
        {
            List<Coupon> ans = new List<Coupon>();

            couponsEntities ce = new couponsEntities();

            List<Coupon> couponList = ce.Coupons.ToList();

            foreach (Coupon c in couponList)
            {
                if (c.Category.Name.Equals(myPreference)) //category match
                {
                    //check distance from user to the coupon business

                    double longDiff = (double)c.Business.Long-longt;
                    double latDiff = (double)c.Business.Lat-lat;
                    double distance = Math.Sqrt(longDiff+latDiff);

                    if (distance<10) //change 10
                        ans.Add(c);
                }

            }

            return ans;
        }
Ejemplo n.º 4
0
 //Shows all the reccomndation according to the reccomandation system
 protected void btn_ShowRecommandation_Click(object sender, EventArgs e)
 {
     couponsEntities ce = new couponsEntities();
     IRecommandation recSys = (IRecommandation)Session["RecommandationSystem"];
     List<Coupon> recommandedCoupons = recSys.findCoupons();
     MyCoupons.DataSource = recommandedCoupons;
     MyCoupons.DataBind();
 }
Ejemplo n.º 5
0
 private void editBusiness(int businessID)
 {
     couponsEntities ce = new couponsEntities();
     Business b = ce.Businesses.Find(businessID);
     txt_Name.Text = b.Name;
     txt_Address.Text = b.Address;
     txt_City.Text = b.City;
     txt_Description.Text = b.Description;
     Label6.Text = "ID: " + businessID;
     editBusinessDiv.Visible = true;
 }
Ejemplo n.º 6
0
 protected void submit_edit_Click(object sender, EventArgs e)
 {
     couponsEntities ce = new couponsEntities();
     Business b = ce.Businesses.Find(Int32.Parse(Label6.Text.Substring(4)));
     b.Name = txt_Name.Text;
     b.Description = txt_Description.Text;
     b.Address = txt_Address.Text;
     b.City = txt_City.Text;
     editBusinessDiv.Visible = false;
     ce.Entry(b).State = System.Data.Entity.EntityState.Modified; //check!!!!
     ce.SaveChanges();
 }
Ejemplo n.º 7
0
 protected void submit_edit_Click(object sender, EventArgs e)
 {
     couponsEntities ce = new couponsEntities();
     Coupon c = ce.Coupons.Find(Int32.Parse(Label8.Text.Substring(4)));
     c.Name = txt_Name.Text;
     c.Type = Convert.ToInt32(txt_Type.Text);
     c.OriginalPrice = Convert.ToInt32(txt_OriginalPrice.Text);
     c.DiscountPrice = Convert.ToInt32(txt_DiscountPrice.Text);
     c.Description = txt_Description.Text;
     editCouponDiv.Visible = false;
     ce.Entry(c).State = System.Data.Entity.EntityState.Modified; //check!!!!
     ce.SaveChanges();
 }
Ejemplo n.º 8
0
        protected void Page_Load(object sender, EventArgs e)
        {
            //Check For Cookies:
            HttpCookieCollection cookieCollection = Request.Cookies;

            HttpCookie cookie = cookieCollection["CouponCookie"];

            if (cookie != null)
            {
                string uName = cookie["UserName"];
                string lastEntered = cookie["LastEntered"];
                string uType = cookie["UserType"];
                if (uName != null)
                {
                    Session["CurrentUserName"] = uName;
                    Session["LastEntered"] = lastEntered;
                    Session["CurrentUserType"] = uType;
                    cookie["LastEntered"] = DateTime.Now.ToString();
                    Response.Cookies.Add(cookie);
                    if (uType.Equals("1")) //Admin
                        Response.Redirect("~/AdminHomePage.aspx");
                    else if (uType.Equals("3")) //Business Manager
                        Response.Redirect("~/BusinessManagerHomePage.aspx");
                    else
                        Response.Redirect("HomePage.aspx");
                }

            }
            else //No Such Cookie. Guests area
            {

                //Populate the GridView:
                couponsEntities bse = new couponsEntities();
                List<Coupon> lst = bse.Coupons.ToList();
                List<Coupon> lst_newCoupons = new List<Coupon>();
                foreach (Coupon c in lst)
                {
                    string cName = c.Name;
                    double price = c.DiscountPrice;

                    if (price < 100) //add to cheap list
                    {
                        lst_newCoupons.Add(c);
                    }
                }
                NewCoupons.DataSource = lst_newCoupons;
                NewCoupons.AutoGenerateColumns = false;
                NewCoupons.DataBind();
            }
        }
Ejemplo n.º 9
0
 private void editCoupon(int couponID)
 {
     couponsEntities ce = new couponsEntities();
     Coupon c = ce.Coupons.Find(couponID);
     txt_Name.Text = c.Name;
     txt_Type.Text = Convert.ToString(c.Type);
     txt_OriginalPrice.Text = Convert.ToString(c.OriginalPrice);
     txt_DiscountPrice.Text = Convert.ToString(c.DiscountPrice);
     txt_Description.Text = c.Description;
     txt_DiscountPrice.Text = c.DiscountPrice.ToString();
     txt_OriginalPrice.Text = c.OriginalPrice.ToString();
     Label8.Text = "ID: " + couponID;
     editCouponDiv.Visible = true;
 }
Ejemplo n.º 10
0
 protected void btn_Submit_Click(object sender, EventArgs e)
 {
     Business b = new Business();
     b.Name = txt_name.Text;
     b.Address = txt_Address.Text;
     b.City = txt_city.Text;
     b.Description = txt_description.Text;
     b.Long = Convert.ToDouble(txt_long.Text);
     b.Lat = Convert.ToDouble(txt_Lat.Text);
     //business manager
     couponsEntities ce = new couponsEntities();
     ce.Businesses.Add(b);
     ce.SaveChanges();
 }
Ejemplo n.º 11
0
        public void CheckRecByLocation()
        {
            couponsEntities ce = new couponsEntities();
            List<Coupon> lst = new List<Coupon>();
            ByPreference bl = new ByPreference("Shopping");
            lst = bl.findCoupons();
            List<Coupon> compareList = ce.Coupons.ToList();
            foreach (Coupon c in compareList)
            {
                if (!c.Category.Name.Equals("Shopping"))
                {
                    compareList.Remove(c);
                }
            }

            Assert.IsTrue(compareList.Count == lst.Count); //check
        }
Ejemplo n.º 12
0
        public List<Coupon> findCoupons()
        {
            List<Coupon> ans = new List<Coupon>();

            couponsEntities ce = new couponsEntities();

            List<Coupon> couponList = ce.Coupons.ToList();

            foreach (Coupon c in couponList)
            {
                if (c.Category.Name.Equals(myPreference))
                    ans.Add(c);
            }

            return ans;
        }