示例#1
0
    public static void AddBrandName(Tbl_Brand brand)
    {
        using (cos_OtherEntities model = new cos_OtherEntities())
        {
            //Tbl_Brand item = new Tbl_Brand();

            var original = model.Tbl_Brands.Where(c => c.BrandID.Equals(brand.BrandID)).SingleOrDefault();

            if (original != null)
            {
                //original.ISRun = isRun;
                original.ISRun      = brand.ISRun;
                original.MinPrice   = brand.MinPrice;
                original.MaxPrice   = brand.MaxPrice;
                original.RangePrice = brand.RangePrice;
                model.SaveChanges();
                model.Dispose();
            }
            else
            {
                //item.BrandName = brand.BrandName;
                //item.CategoryID = brand.CategoryID;
                //item.ISRun = false;
                model.AddToTbl_Brands(brand);
                model.SaveChanges();
            }
        }
    }
示例#2
0
    protected void btnAdd_Click(object sender, EventArgs e)
    {
        Tbl_Brand item = new Tbl_Brand();

        item.BrandName  = txtBrandName.Text.Trim();
        item.CategoryID = Convert.ToInt32(UC_CategoryList.SelectedValue.ToString());
        item.ISRun      = false;
        clsAddItems.AddBrandName(item);
        BindBrand();
        //txtBrandName.Text
    }
示例#3
0
    public static void AddBrandName(bool isRun, int BrandID)
    {
        using (cos_OtherEntities model = new cos_OtherEntities())
        {
            Tbl_Brand item = new Tbl_Brand();

            var original = model.Tbl_Brands.Where(c => c.BrandID.Equals(BrandID)).SingleOrDefault();

            if (original != null)
            {
                original.ISRun = isRun;
                model.SaveChanges();
                model.Dispose();
            }
        }
    }
示例#4
0
        public ActionResult UpdateBrand(BrandDetail cd, HttpPostedFileBase _BrandImage)
        {
            int poz = 0;

            if (ModelState.IsValid)
            {
                Tbl_Brand b = _unitOfWork.GetRepositoryInstance <Tbl_Brand>().GetFirstOrDefault(cd.BrandId);
                b           = b != null ? b : new Tbl_Brand();
                b.BrandName = cd.BrandName;
                if (_BrandImage != null)
                {
                    for (int i = _BrandImage.FileName.Length - 4; i >= 0; i--)
                    {
                        if (_BrandImage.FileName[i] == '\\')
                        {
                            poz = i;
                            break;
                        }
                    }
                }
                b.BrandImage = _BrandImage != null?_BrandImage.FileName.Substring(poz + 1) : b.BrandImage;

                if (cd.BrandId != 0)
                {
                    _unitOfWork.GetRepositoryInstance <Tbl_Brand>().Update(b);
                    _unitOfWork.SaveChanges();
                }
                else
                {
                    b.IsActive = true;
                    b.IsDelete = false;
                    _unitOfWork.GetRepositoryInstance <Tbl_Brand>().Add(b);
                }

                return(RedirectToAction("Brands"));

                if (_BrandImage != null)
                {
                    uc.UploadImage(_BrandImage, b.BrandId + "_", "/Content/ProductImage/", Server, _unitOfWork, 0, b.BrandId, 0);
                }
                return(RedirectToAction("Products"));
            }
            else
            {
                return(View("UpdateBrand", cd));
            }
        }
示例#5
0
    protected void btnUpdate_Click(object sender, EventArgs e)
    {
        List <Tbl_Brand> brands = new List <Tbl_Brand>();

        foreach (GridViewRow row in gvItems.Rows)
        {
            Tbl_Brand brand         = new Tbl_Brand();
            TextBox   txtMinPrice   = (TextBox)row.FindControl("txtMinPrice");
            TextBox   txtMaxPrice   = (TextBox)row.FindControl("txtMaxPrice");
            TextBox   txtRangePrice = (TextBox)row.FindControl("txtRangePrice");
            if (!string.IsNullOrEmpty(txtMinPrice.Text))
            {
                brand.MinPrice = Convert.ToInt32(txtMinPrice.Text);
            }

            if (!string.IsNullOrEmpty(txtMaxPrice.Text))
            {
                brand.MaxPrice = Convert.ToInt32(txtMaxPrice.Text);
            }

            if (!string.IsNullOrEmpty(txtRangePrice.Text))
            {
                brand.RangePrice = Convert.ToInt32(txtRangePrice.Text);
            }

            int brandID = Convert.ToInt32(gvItems.DataKeys[row.RowIndex].Value);
            brand.BrandID = brandID;
            if (((CheckBox)row.FindControl("chkRow")).Checked)
            {
                // brand.ISRun = true;
            }
            else
            {
                //  brand.ISRun = false;
            }
            brands.Add(brand);
        }

        if (brands.Count > 0)
        {
            clsAddItems.AddBrandName(brands);
            BindBrand();
        }
    }
示例#6
0
        public ActionResult AddBrand(Tbl_Brand brand)
        {
            var validImageTypes = new string[]
            {
                "image/gif",
                "image/jpg",
                "image/jpeg",
                "image/pjpeg",
                "image/png"
            };
            String Message = "";

            if (Session["UserName"] == null)
            {
                Message = "Access denied. need login.";
                log.addLog(Message, "AddBrand", "DashboardBrand", logStatus.EventLog);
                return(RedirectToAction("Index", "Account", new { returnUrl = "/DashboardBrand/Index" }));
            }
            else if (Session["RoleName"].ToString() == "Admin")
            {
                try
                {
                    Tbl_Brand b = new Tbl_Brand();
                    b.Brand_Title = brand.Brand_Title;
                    if (brand.Brand_ImageIndex != null)
                    {
                        var    uploadFiles = Request.Files[0];
                        Random rnd         = new Random();

                        if (!validImageTypes.Contains(uploadFiles.ContentType))
                        {
                            Message = "invalid image format.";
                            log.addLog(Message, "AddBrand", "DashboardBrand", logStatus.EventLog);
                            ViewBag.Error = "عکس آپلود شده باید از نوع jpg ویا png باشد.";
                            return(View());
                        }
                        else if (uploadFiles != null && uploadFiles.ContentLength > 0)
                        {
                            var fileName = rnd.Next().ToString() + ".jpg";
                            b.Brand_ImageIndex = fileName;
                            var path = Path.Combine(System.Web.HttpContext.Current.Server.MapPath("/Uploads/BrandImages/"), fileName);
                            uploadFiles.SaveAs(path);
                            Message = "Image save successfully for brand with title " + brand.Brand_Title + ".";
                            log.addLog(Message, "AddBrand", "DashboardBrand", logStatus.EventLog);
                            db.Tbl_Brand.Add(b);
                            if (Convert.ToBoolean(db.SaveChanges() > 0))
                            {
                                Message = "Brand with title " + brand.Brand_Title + " added successfully.";
                                log.addLog(Message, "AddBrand", "DashboardBrand", logStatus.EventLog);
                                return(RedirectToAction("Index", "DashboardBrand"));
                            }
                            else
                            {
                                Message = "added Brand with title " + brand.Brand_Title + " failed.";
                                log.addLog(Message, "AddBrand", "DashboardBrand", logStatus.EventLog);
                                ViewBag.Error = "برند جدید ثبت نشد، لطفا دوباره تلاش کنید.";
                                return(View());
                            }
                        }
                        else
                        {
                            Message = "Image save for brand with title " + b.Brand_Title + " failed.";
                            log.addLog(Message, "AddBrand", "DashboardBrand", logStatus.EventLog);
                            ViewBag.EmptyImage = "آپلود عکس با خطا مواجه شده است.";
                            return(View());
                        }
                    }
                    else
                    {
                        Message = "Image save for brand with title " + b.Brand_Title + " failed.";
                        log.addLog(Message, "AddBrand", "DashboardBrand", logStatus.EventLog);
                        ViewBag.EmptyImage = "آپلود عکس با خطا مواجه شده است.";
                        return(View());
                    }
                }
                catch
                {
                    Message = "added brand with title " + brand.Brand_Title + " failed.";
                    log.addLog(Message, "AddBrand", "DashboardBrand", logStatus.ErrorLog);
                    ViewBag.Error = "برند جدید ثبت نشد، لطفا دوباره تلاش کنید.";
                    return(View());
                }
            }
            else
            {
                Message = "Access denied. need login.";
                log.addLog(Message, "AddBrand", "DashboardBrand", logStatus.EventLog);
                return(RedirectToAction("Index", "Account", new { returnUrl = "/DashboardBrand/Index" }));
            }
        }