示例#1
0
        public HttpResponseMessage add(ProductAccessory post)
        {
            // Check for errors
            if (post == null)
            {
                return(Request.CreateResponse <string>(HttpStatusCode.BadRequest, "The post is null"));
            }
            else if (Product.MasterPostExists(post.product_id) == false)
            {
                return(Request.CreateResponse <string>(HttpStatusCode.BadRequest, "The product does not exist"));
            }
            else if (Product.MasterPostExists(post.accessory_id) == false)
            {
                return(Request.CreateResponse <string>(HttpStatusCode.BadRequest, "The accessory does not exist"));
            }
            else if (ProductAccessory.GetOneById(post.product_id, post.accessory_id) != null)
            {
                return(Request.CreateResponse <string>(HttpStatusCode.BadRequest, "The product accessory already exists"));
            }

            // Add the post
            ProductAccessory.Add(post);

            // Return the success response
            return(Request.CreateResponse <string>(HttpStatusCode.OK, "The post has been added"));
        } // End of the add method
        public HttpResponseMessage add(ProductAccessory post)
        {
            // Check for errors
            if (post == null)
            {
                return Request.CreateResponse<string>(HttpStatusCode.BadRequest, "The post is null");
            }
            else if (Product.MasterPostExists(post.product_id) == false)
            {
                return Request.CreateResponse<string>(HttpStatusCode.BadRequest, "The product does not exist");
            }
            else if (Product.MasterPostExists(post.accessory_id) == false)
            {
                return Request.CreateResponse<string>(HttpStatusCode.BadRequest, "The accessory does not exist");
            }
            else if(ProductAccessory.GetOneById(post.product_id, post.accessory_id) != null)
            {
                return Request.CreateResponse<string>(HttpStatusCode.BadRequest, "The product accessory already exists");
            }

            // Add the post
            ProductAccessory.Add(post);

            // Return the success response
            return Request.CreateResponse<string>(HttpStatusCode.OK, "The post has been added");

        } // End of the add method
示例#3
0
        public List <Product> get_by_product_id(Int32 id = 0, Int32 languageId = 0, string sortField = "", string sortOrder = "")
        {
            // Create the list to return
            List <Product> posts = ProductAccessory.GetByProductId(id, languageId, sortField, sortOrder);

            // Return the list
            return(posts);
        } // End of the get_by_product_id method
示例#4
0
        public ActionResult DeleteConfirmed(int id)
        {
            ProductAccessory productAccessory = db.ProductAccessories.Find(id);

            db.ProductAccessories.Remove(productAccessory);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
示例#5
0
        public ProductAccessory get_by_id(Int32 id = 0, Int32 accessoryId = 0)
        {
            // Create the post to return
            ProductAccessory post = ProductAccessory.GetOneById(id, accessoryId);

            // Return the post
            return(post);
        } // End of the get_by_id method
示例#6
0
        public List <ProductAccessory> get_all()
        {
            // Create the list to return
            List <ProductAccessory> posts = ProductAccessory.GetAll();

            // Return the list
            return(posts);
        } // End of the get_all method
示例#7
0
    } // End of the Add method

    #endregion

    #region Get methods

    /// <summary>
    /// Get one product accessory on id
    /// </summary>
    /// <param name="productId">A product id</param>
    /// <param name="accessoryId">An accessory id</param>
    /// <returns>A reference to a product accessory post</returns>
    public static ProductAccessory GetOneById(Int32 productId, Int32 accessoryId)
    {
        // Create the post to return
        ProductAccessory post = null;

        // Create the connection and the sql statement
        string connection = Tools.GetConnectionString();
        string sql = "SELECT * FROM dbo.product_accessories WHERE product_id = @product_id AND " 
            + "accessory_id = @accessory_id;";

        // The using block is used to call dispose automatically even if there are an exception.
        using (SqlConnection cn = new SqlConnection(connection))
        {
            // The using block is used to call dispose automatically even if there are an exception.
            using (SqlCommand cmd = new SqlCommand(sql, cn))
            {
                // Add parameters
                cmd.Parameters.AddWithValue("@product_id", productId);
                cmd.Parameters.AddWithValue("@accessory_id", accessoryId);

                // Create a reader
                SqlDataReader reader = null;

                // The Try/Catch/Finally statement is used to handle unusual exceptions in the code to
                // avoid having our application crash in such cases.
                try
                {
                    // Open the connection.
                    cn.Open();

                    // Fill the reader with one row of data.
                    reader = cmd.ExecuteReader();

                    // Loop through the reader as long as there is something to read and add values
                    while (reader.Read())
                    {
                        post = new ProductAccessory(reader);
                    }
                }
                catch (Exception e)
                {
                    throw e;
                }
                finally
                {
                    // Call Close when done reading to avoid memory leakage.
                    if (reader != null)
                        reader.Close();
                }
            }
        }

        // Return the post
        return post;

    } // End of the GetOneById method
示例#8
0
 public ActionResult Edit([Bind(Include = "ProductAccessoryId,ProductId,Color,Price,ImageFile,Quantiny")] ProductAccessory productAccessory)
 {
     if (ModelState.IsValid)
     {
         db.Entry(productAccessory).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.ProductId = new SelectList(db.Products, "ProductId", "ProductName", productAccessory.ProductId);
     return(View(productAccessory));
 }
        public JsonResult Update(int productID, string products)
        {
            var jsonSuccessResult = new JsonSuccessResult();

            try
            {
                string[] arrProducts = products.Split(',');

                // حذف
                #region Delete All

                ProductAccessories.DeleteProductAccessories(productID);

                #endregion Delete All

                // ثبت مجدد
                #region Add

                List <ProductAccessory> listItems = new List <ProductAccessory>();

                foreach (var item in arrProducts)
                {
                    if (!String.IsNullOrWhiteSpace(item))
                    {
                        ProductAccessory product = new ProductAccessory
                        {
                            ProductID   = productID,
                            AccessoryID = Int32.Parse(item),
                            LastUpdate  = DateTime.Now,
                        };

                        listItems.Add(product);
                    }
                }

                ProductAccessories.Insert(listItems);

                #endregion Add

                jsonSuccessResult.Success = true;
            }
            catch (Exception ex)
            {
                jsonSuccessResult.Errors  = new string[] { ex.Message };
                jsonSuccessResult.Success = false;
            }

            return(new JsonResult()
            {
                Data = jsonSuccessResult
            });
        }
示例#10
0
        // GET: Admin/ProductAccessories/Details/5
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            ProductAccessory productAccessory = db.ProductAccessories.Find(id);

            if (productAccessory == null)
            {
                return(HttpNotFound());
            }
            return(View(productAccessory));
        }
示例#11
0
        public void InsertProductAccessory(int productSysNo, ProductAccessory productAccessory)
        {
            DataCommand dc = DataCommandManager.GetDataCommand("InsertProductAccessory");

            dc.SetParameterValue("@ProductSysNo", productSysNo);
            dc.SetParameterValue("@AccessoriesSysno", productAccessory.AccessoryInfo.SysNo);
            dc.SetParameterValue("@Status", productAccessory.Status);
            dc.SetParameterValue("@Qty", productAccessory.Qty);
            dc.SetParameterValue("@Description", productAccessory.Description.Content);
            dc.SetParameterValue("@ListOrder", productAccessory.Priority);
            dc.SetParameterValue("@InUserSysNo", productAccessory.OperationUser.SysNo);
            dc.SetParameterValue("@CompanyCode", productAccessory.CompanyCode);
            dc.SetParameterValue("@LanguageCode", productAccessory.LanguageCode);
            dc.ExecuteNonQuery();
        }
示例#12
0
        // GET: Admin/ProductAccessories/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            ProductAccessory productAccessory = db.ProductAccessories.Find(id);

            if (productAccessory == null)
            {
                return(HttpNotFound());
            }
            ViewBag.ProductId = new SelectList(db.Products, "ProductId", "ProductName", productAccessory.ProductId);
            return(View(productAccessory));
        }
示例#13
0
        public HttpResponseMessage delete(Int32 id = 0, Int32 accessoryId = 0)
        {
            // Create an error code variable
            Int32 errorCode = 0;

            // Delete the post
            errorCode = ProductAccessory.DeleteOnId(id, accessoryId);

            // Check if there is an error
            if (errorCode != 0)
            {
                return(Request.CreateResponse <string>(HttpStatusCode.Conflict, "Foreign key constraint"));
            }

            // Return the success response
            return(Request.CreateResponse <string>(HttpStatusCode.OK, "The delete was successful"));
        } // End of the delete method
示例#14
0
        public ActionResult Create([Bind(Include = "ProductAccessoryId,ProductId,Color,Price,ImageFile,Quantiny")] ProductAccessory productAccessory, HttpPostedFileBase imageFront, HttpPostedFileBase imageBack, HttpPostedFileBase imageSide)
        {
            if (ModelState.IsValid)
            {
                db.ProductAccessories.Add(productAccessory);
                db.SaveChanges();
                if (imageFront != null)
                {
                    //Resize Image
                    WebImage img = new WebImage(imageFront.InputStream);
                    img.Resize(500, 1000);

                    var    filePathOriginal = Server.MapPath("/Assets/user/images");
                    var    fileName         = productAccessory.ProductId + "-" + productAccessory.Color + "-1" + ".jpg";
                    string savedFileName    = Path.Combine(filePathOriginal, fileName);
                    img.Save(savedFileName);
                }
                if (imageBack != null)
                {
                    //Resize Image
                    WebImage img = new WebImage(imageBack.InputStream);
                    img.Resize(500, 1000);

                    var    filePathOriginal = Server.MapPath("/Assets/user/images");
                    var    fileName         = productAccessory.ProductId + "-" + productAccessory.Color + "-2" + ".jpg";
                    string savedFileName    = Path.Combine(filePathOriginal, fileName);
                    img.Save(savedFileName);
                }
                if (imageSide != null)
                {
                    //Resize Image
                    WebImage img = new WebImage(imageSide.InputStream);
                    img.Resize(500, 1000);

                    var    filePathOriginal = Server.MapPath("/Assets/user/images");
                    var    fileName         = productAccessory.ProductId + "-" + productAccessory.Color + "-3" + ".jpg";
                    string savedFileName    = Path.Combine(filePathOriginal, fileName);
                    img.Save(savedFileName);
                }
                return(RedirectToAction("Index"));
            }

            ViewBag.ProductId = new SelectList(db.Products, "ProductId", "ProductName", productAccessory.ProductId);
            return(View(productAccessory));
        }
示例#15
0
    } // End of the constructor

    #endregion

    #region Insert methods

    /// <summary>
    /// Add one product accessory
    /// </summary>
    /// <param name="post">A reference to a product accessory post</param>
    public static void Add(ProductAccessory post)
    {

        // Create the connection and the sql statement
        string connection = Tools.GetConnectionString();
        string sql = "INSERT INTO dbo.product_accessories (product_id, accessory_id) "
            + "VALUES (@product_id, @accessory_id);";

        // The using block is used to call dispose automatically even if there are an exception.
        using (SqlConnection cn = new SqlConnection(connection))
        {
            // The using block is used to call dispose automatically even if there are an exception.
            using (SqlCommand cmd = new SqlCommand(sql, cn))
            {
                // Add parameters
                cmd.Parameters.AddWithValue("@product_id", post.product_id);
                cmd.Parameters.AddWithValue("@accessory_id", post.accessory_id);

                // The Try/Catch/Finally statement is used to handle unusual exceptions in the code to
                // avoid having our application crash in such cases
                try
                {
                    // Open the connection
                    cn.Open();

                    // Execute the insert
                    cmd.ExecuteNonQuery();

                }
                catch (Exception e)
                {
                    throw e;
                }
            }
        }

    } // End of the Add method
示例#16
0
    } // End of the constructor

    #endregion

    #region Insert methods

    /// <summary>
    /// Add one product accessory
    /// </summary>
    /// <param name="post">A reference to a product accessory post</param>
    public static void Add(ProductAccessory post)
    {
        // Create the connection and the sql statement
        string connection = Tools.GetConnectionString();
        string sql = "INSERT INTO dbo.product_accessories (product_id, accessory_id) "
            + "VALUES (@product_id, @accessory_id);";

        // The using block is used to call dispose automatically even if there are an exception.
        using (SqlConnection cn = new SqlConnection(connection))
        {
            // The using block is used to call dispose automatically even if there are an exception.
            using (SqlCommand cmd = new SqlCommand(sql, cn))
            {
                // Add parameters
                cmd.Parameters.AddWithValue("@product_id", post.product_id);
                cmd.Parameters.AddWithValue("@accessory_id", post.accessory_id);

                // The Try/Catch/Finally statement is used to handle unusual exceptions in the code to
                // avoid having our application crash in such cases
                try
                {
                    // Open the connection
                    cn.Open();

                    // Execute the insert
                    cmd.ExecuteNonQuery();

                }
                catch (Exception e)
                {
                    throw e;
                }
            }
        }

    } // End of the Add method
示例#17
0
        public static List <ProductBase> FillProducts()
        {
            OleDbConnection con     = new OleDbConnection(SqlConnection);
            OleDbCommand    command = new OleDbCommand("SELECT * FROM TB_PRODUCT", con);

            command.CommandTimeout = 60000;

            List <ProductBase> products = new List <ProductBase>();

            try
            {
                con.Open();

                using (OleDbDataReader reader = command.ExecuteReader())
                {
                    if (reader.HasRows)
                    {
                        while (reader.Read())
                        {
                            ProductBase product = null;
                            string      type    = String.Empty;

                            if (!reader.IsDBNull(reader.GetOrdinal("Type")))
                            {
                                type = reader.GetString(reader.GetOrdinal("Type"));
                            }

                            if (type.Equals("tablet"))
                            {
                                product = new ProductTablet();

                                if (!reader.IsDBNull(reader.GetOrdinal("Size")))
                                {
                                    ((ProductTablet)product).Size = reader.GetString(reader.GetOrdinal("Size"));
                                }
                            }
                            else if (type.Equals("accessory"))
                            {
                                product = new ProductAccessory();

                                if (!reader.IsDBNull(reader.GetOrdinal("Color")))
                                {
                                    ((ProductAccessory)product).Color = reader.GetString(reader.GetOrdinal("Color"));
                                }
                            }


                            //-->COPY THIS PART

                            if (!reader.IsDBNull(reader.GetOrdinal("ID")))
                            {
                                product.Id = reader.GetInt32(reader.GetOrdinal("ID"));
                            }

                            if (!reader.IsDBNull(reader.GetOrdinal("SKU")))
                            {
                                product.SKU = reader.GetString(reader.GetOrdinal("SKU"));
                            }

                            product.Type = type;

                            if (!reader.IsDBNull(reader.GetOrdinal("Name")))
                            {
                                product.Name = reader.GetString(reader.GetOrdinal("Name"));
                            }

                            if (!reader.IsDBNull(reader.GetOrdinal("Description")))
                            {
                                product.Description = reader.GetString(reader.GetOrdinal("Description"));
                            }

                            if (!reader.IsDBNull(reader.GetOrdinal("Img")))
                            {
                                product.Img = reader.GetString(reader.GetOrdinal("Img"));
                            }

                            //SET! IN ProductBase
                            if (!reader.IsDBNull(reader.GetOrdinal("Price")))
                            {
                                product.Price = reader.GetDouble(reader.GetOrdinal("Price"));
                            }


                            //<--COPY THIS PART

                            products.Add(product);
                        }
                    }
                }
            }
            catch
            {
                throw;
            }
            finally
            {
                if (con != null)
                {
                    con.Close();
                }
            }

            return(products);
        }
示例#18
0
    } // End of the Add method

    #endregion

    #region Get methods

    /// <summary>
    /// Get one product accessory on id
    /// </summary>
    /// <param name="productId">A product id</param>
    /// <param name="accessoryId">An accessory id</param>
    /// <returns>A reference to a product accessory post</returns>
    public static ProductAccessory GetOneById(Int32 productId, Int32 accessoryId)
    {
        // Create the post to return
        ProductAccessory post = null;

        // Create the connection and the sql statement
        string connection = Tools.GetConnectionString();
        string sql = "SELECT * FROM dbo.product_accessories WHERE product_id = @product_id AND " 
            + "accessory_id = @accessory_id;";

        // The using block is used to call dispose automatically even if there are an exception.
        using (SqlConnection cn = new SqlConnection(connection))
        {
            // The using block is used to call dispose automatically even if there are an exception.
            using (SqlCommand cmd = new SqlCommand(sql, cn))
            {
                // Add parameters
                cmd.Parameters.AddWithValue("@product_id", productId);
                cmd.Parameters.AddWithValue("@accessory_id", accessoryId);

                // Create a reader
                SqlDataReader reader = null;

                // The Try/Catch/Finally statement is used to handle unusual exceptions in the code to
                // avoid having our application crash in such cases.
                try
                {
                    // Open the connection.
                    cn.Open();

                    // Fill the reader with one row of data.
                    reader = cmd.ExecuteReader();

                    // Loop through the reader as long as there is something to read and add values
                    while (reader.Read())
                    {
                        post = new ProductAccessory(reader);
                    }
                }
                catch (Exception e)
                {
                    throw e;
                }
                finally
                {
                    // Call Close when done reading to avoid memory leakage.
                    if (reader != null)
                        reader.Close();
                }
            }
        }

        // Return the post
        return post;

    } // End of the GetOneById method
示例#19
0
        public ProductBase GetProductBaseFromRecord(OleDbDataReader reader)
        {
            ProductBase product = null;
            string      type    = String.Empty;

            if (!reader.IsDBNull(reader.GetOrdinal("Type")))
            {
                type = reader.GetString(reader.GetOrdinal("Type"));
            }

            if (type.Equals("tablet"))
            {
                product = new ProductTablet();

                if (!reader.IsDBNull(reader.GetOrdinal("Size")))
                {
                    ((ProductTablet)product).Size = reader.GetString(reader.GetOrdinal("Size"));
                }
            }
            else if (type.Equals("accessory"))
            {
                product = new ProductAccessory();

                if (!reader.IsDBNull(reader.GetOrdinal("Color")))
                {
                    ((ProductAccessory)product).Color = reader.GetString(reader.GetOrdinal("Color"));
                }
            }

            if (product != null)
            {
                if (!reader.IsDBNull(reader.GetOrdinal("ID")))
                {
                    product.Id = reader.GetInt32(reader.GetOrdinal("ID"));
                }

                if (!reader.IsDBNull(reader.GetOrdinal("SKU")))
                {
                    product.SKU = reader.GetString(reader.GetOrdinal("SKU"));
                }

                product.Type = type;

                if (!reader.IsDBNull(reader.GetOrdinal("Name")))
                {
                    product.Name = reader.GetString(reader.GetOrdinal("Name"));
                }

                if (!reader.IsDBNull(reader.GetOrdinal("Description")))
                {
                    product.Description = reader.GetString(reader.GetOrdinal("Description"));
                }

                if (!reader.IsDBNull(reader.GetOrdinal("Img")))
                {
                    product.Img = reader.GetString(reader.GetOrdinal("Img"));
                }

                //SET! IN ProductBase
                //if (!reader.IsDBNull(reader.GetOrdinal("Price")))
                //    product.Price = reader.GetDouble(reader.GetOrdinal("Price"));
            }
            return(product);
        }
        public ActionResult add_accessory(Int32 productId = 0, Int32 accessoryId = 0, string returnUrl = "")
        {
            // Get the current domain
            Domain currentDomain = Tools.GetCurrentDomain();
            ViewBag.CurrentDomain = currentDomain;

            // Get query parameters
            ViewBag.QueryParams = new QueryParams(returnUrl);

            // Check if the administrator is authorized
            if (Administrator.IsAuthorized(new string[] { "Administrator", "Editor" }) == true)
            {
                ViewBag.AdminSession = true;
            }
            else if (Administrator.IsAuthorized(Administrator.GetAllAdminRoles()) == true)
            {
                ViewBag.AdminSession = true;
                ViewBag.AdminErrorCode = 1;
                ViewBag.TranslatedTexts = StaticText.GetAll(currentDomain.back_end_language, "id", "ASC");
                return View("index");
            }
            else
            {
                // Redirect the user to the start page
                return RedirectToAction("index", "admin_login");
            }

            // Make sure that the product id or accessory id not is 0
            if(productId == 0 || accessoryId == 0)
            {
                return Redirect("/admin_products" + returnUrl);
            }

            // Check if we can find a saved accessory post
            ProductAccessory accessory = ProductAccessory.GetOneById(productId, accessoryId);

            // Make sure that the accessory does not exist already
            if(accessory == null)
            {
                accessory = new ProductAccessory();
                accessory.product_id = productId;
                accessory.accessory_id = accessoryId;
                ProductAccessory.Add(accessory);
            }

            // Return the accessory view
            return RedirectToAction("accessories", new { id = productId, returnUrl = returnUrl });

        } // End of the add_accessory method