示例#1
0
        public bool addApparel(AddApparel model, out string AppID)
        {
            AdminDal obj = new AdminDal();
            model.apparel.ApparelCategory = UtilityFunctions.parseInputCategoryToDBFormat(model.apparel.ApparelCategory);
            model.apparel.ApparelImage = "/"+AdminController.ImagePath;
            string fullPath = HttpContext.Current.Server.MapPath("~/") + AdminController.ImagePath;
            if (model.apparel.ApparelImage == null)
                model.apparel.ApparelImage = string.Empty;
            if (obj.AddProduct(model, out AppID))
            {
                System.IO.File.Move( fullPath+"TempImage.jpg", fullPath + AppID + ".jpg");
                return true;
            }

            return false;
        }
        public ActionResult Apparel(AddApparel model)
        {
            if (!CheckAdmin())
                return (View("~/Views/Shared/Unauthorized.cshtml"));

            ViewBag.categoryData = UtilityFunctions.getCategoryDropDown();
            AdminBLL obj = new AdminBLL();
            string AppID;
            bool result = obj.addApparel(model, out AppID);
            if (result)
            {
                ViewBag.Message = "Sucessfully added apparel";
            }

            else
                ViewBag.Message = "Unable to add apparel";

            return View(model);
        }
示例#3
0
        public bool AddProduct(AddApparel product, out string AppID)
        {
            bool status = false;
            AppID = "";
            //string AppID, imagePath;
            HttpContext.Current.Session["status"] = "DefaultMessage";
                string conStr = ConfigurationManager.ConnectionStrings["FashionableMeDB"].ConnectionString;
                SqlConnection conn = new SqlConnection(conStr);
            try
            {
                conn.Open();
                SqlCommand cmd = new SqlCommand(@"INSERT INTO Apparel OUTPUT INSERTED.ApparelID values (@name,@bname,@desc, CONCAT( @imagepath, CAST( IDENT_CURRENT('Apparel') as NVARCHAR), '.jpg'  ) , @category, GETDATE(),0)", conn);

                cmd.Parameters.AddWithValue("name",product.apparel.ApparelName);
                cmd.Parameters.AddWithValue("bname",product.apparel.BrandName);
                cmd.Parameters.AddWithValue("desc",product.apparel.Description);
                cmd.Parameters.AddWithValue("imagepath", product.apparel.ApparelImage);
                cmd.Parameters.AddWithValue("category",product.apparel.ApparelCategory.Trim());
                AppID = Convert.ToString(cmd.ExecuteScalar());

                SqlCommand cmd2 = new SqlCommand("INSERT into Quantity values ( IDENT_CURRENT('Apparel'), @size, @quantity, @discount, @cost ) ", conn);
                if (product.small > 0)
                {
                    cmd2.Parameters.AddWithValue("size", "S");
                    cmd2.Parameters.AddWithValue("quantity", product.small);
                    cmd2.Parameters.AddWithValue("discount", product.apparel.ApparelDiscount);
                    cmd2.Parameters.AddWithValue("cost", product.apparel.ApparelCost);

                int res = cmd2.ExecuteNonQuery();
                status = true;
            }
                SqlCommand cmd3 = new SqlCommand("INSERT into Quantity values ( IDENT_CURRENT('Apparel'), @size, @quantity, @discount, @cost ) ", conn);

                if (product.medium > 0)
                {
                    cmd3.Parameters.AddWithValue("size", "M");
                    cmd3.Parameters.AddWithValue("quantity", product.medium);
                    cmd3.Parameters.AddWithValue("discount", product.apparel.ApparelDiscount);
                    cmd3.Parameters.AddWithValue("cost", product.apparel.ApparelCost);

                    int res = cmd3.ExecuteNonQuery();
                    status = true;
                }
                SqlCommand cmd4 = new SqlCommand("INSERT into Quantity values ( IDENT_CURRENT('Apparel'), @size, @quantity, @discount, @cost ) ", conn);

                if (product.large > 0)
                {
                    cmd4.Parameters.AddWithValue("size", "L");
                    cmd4.Parameters.AddWithValue("quantity", product.large);
                    cmd4.Parameters.AddWithValue("discount", product.apparel.ApparelDiscount);
                    cmd4.Parameters.AddWithValue("cost", product.apparel.ApparelCost);
                    int res = cmd4.ExecuteNonQuery();
                    status = true;
                }
            }
            catch (Exception exc)
            {
                HttpContext.Current.Session["ErrorMessage"] = exc.Message;
            }
            conn.Close();
            return status;
        }
示例#4
0
        public List<AddApparel> GetApparelsByBrandAndName(string name, string brand)
        {
            List<AddApparel> dataRows = new List<AddApparel>();
            string conStr = ConfigurationManager.ConnectionStrings["FashionableMeDB"].ConnectionString;
            SqlConnection conn = new SqlConnection(conStr);
            try
            {
                conn.Open();
                SqlCommand cmd = new SqlCommand("Select ap.ApparelID, ap.ApparelName, ap.BrandName, ap.Description, ap.ApparelCategory, qt.QuantityPerSize, qt.ApparelSize, qt.ApparelDiscount, qt.ApparelCost from Apparel ap INNER JOIN Quantity qt ON ap.ApparelID=qt.ApparelID where ap.BrandName=@brand AND ap.ApparelName=@name", conn);
                cmd.Parameters.AddWithValue("brand", brand.Trim());
                cmd.Parameters.AddWithValue("name", name.Trim());
                var reader = cmd.ExecuteReader();
                if (reader.HasRows)
                {
                    while (reader.Read())
                    {
                        AddApparel prodObj = new AddApparel();
                        prodObj.apparel.ApparelName = reader.GetString(reader.GetOrdinal("ApparelName"));
                        prodObj.apparel.ApparelID = reader.GetInt32(reader.GetOrdinal("ApparelID"));
                        prodObj.apparel.BrandName = reader.GetString(reader.GetOrdinal("BrandName"));
                        prodObj.apparel.ApparelCost = reader.GetDecimal(reader.GetOrdinal("ApparelCost"));
                        prodObj.apparel.Description = reader.GetString(reader.GetOrdinal("Description"));
                        //prodObj.apparel.ApparelImage = reader.GetString(reader.GetOrdinal("ApparelImage"));
                        prodObj.apparel.ApparelCategory = reader.GetString(reader.GetOrdinal("ApparelCategory"));
                        //prodObj.apparel.ApparelRating = reader.GetInt32(reader.GetOrdinal("ApparelRating"));
                        prodObj.apparel.ApparelSize = reader.GetString(reader.GetOrdinal("ApparelSize"));
                        prodObj.apparel.ApparelQuantity = reader.GetInt32(reader.GetOrdinal("QuantityPerSize"));
                        prodObj.apparel.ApparelDiscount = reader.GetDecimal(reader.GetOrdinal("ApparelDiscount"));
                        //if (prodObj.apparel.ApparelSize == "S")
                        //{
                        //    prodObj.small = quant;
                        //    prodObj.costForSmall = prodObj.apparel.ApparelCost;
                        //}
                        //else if (prodObj.apparel.ApparelSize == "M")
                        //{
                        //    prodObj.medium = quant;
                        //    prodObj.costForMedium = prodObj.apparel.ApparelCost;

                        //}
                        //else if (prodObj.apparel.ApparelSize == "L")
                        //{
                        //    prodObj.large = quant;
                        //    prodObj.costForLarge = prodObj.apparel.ApparelCost;

                        //}
                        dataRows.Add(prodObj);
                    }
                }
            }
            catch (Exception ExcObj)
            {
                HttpContext.Current.Session["ErrorMessage"] = ExcObj.Message;
            }
            conn.Close();
            return dataRows;
        }