Exemple #1
0
        public virtual void Update(Image entityToUpdate)
        {
            try
            {
                TblImage tblImage = dbContext.TblImage.Find(entityToUpdate.ImageId);;

                //only update fields touched on the Image Table
                if (tblImage.ImageAlt != entityToUpdate.ImageAlt)
                {
                    tblImage.ImageAlt = entityToUpdate.ImageAlt;
                }
                if (tblImage.ImageName != entityToUpdate.ImageName)
                {
                    tblImage.ImageName = entityToUpdate.ImageName;
                }
                if (tblImage.ImageUrl != entityToUpdate.ImageUrl)
                {
                    tblImage.ImageUrl = entityToUpdate.ImageUrl;
                }
                if (entityToUpdate.AlbumImage != null && entityToUpdate.AlbumImage.Length > 0)
                {
                    tblImage.AlbumImage = entityToUpdate.AlbumImage;
                }
                dbContext.TblImage.Update(tblImage);

                AddRemoveTags(entityToUpdate.ImageId, entityToUpdate.ImageTags);

                this.dbContext.SaveChanges();
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Exemple #2
0
 /// <summary>
 /// delete Image in table TblImage and delete image in folder
 /// </summary>
 /// <param name="id"></param>
 /// <param name="productID"></param>
 /// <returns></returns>
 public ActionResult delete(int id, int productID)
 {
     try
     {
         string   query = "select * from TblImage where ImageID = " + id.ToString();
         TblImage image = connect.Query <TblImage>(query).FirstOrDefault <TblImage>();
         if (image != null)
         {
             string folder    = Server.MapPath("~/assets/uploads/products/") + productID;
             string pathImage = folder + "/" + image.ImageName;
             System.IO.File.Delete(pathImage);
             string where = "ProductID = " + productID + " and ImageID = " + id;
             List <Variant> variants = variantService.GetByWhere(where);
             if (variants != null && variants.Count > 0)
             {
                 foreach (var item in variants)
                 {
                     item.ImageID = null;
                     variantService.Update(item);
                 }
             }
             if (imageService.DeleteByPrimary(id))
             {
                 return(RedirectToAction("detail", "products", new { id = productID, messageDelete = 1 }));
             }
         }
     }
     catch (Exception ex)
     {
         LogService.WriteException(ex);
     }
     return(RedirectToAction("detail", "products", new { id = productID, messageDelete = 0 }));
 }
        public async Task <TblImage> AddImage(TblImage image)
        {
            HttpResponseMessage httpResponseMessage = await _httpClient.PostAsJsonAsync("api/ImageCore/AddImage", image);

            TblImage ans = await httpResponseMessage.Content.ReadAsAsync <TblImage>();

            return(ans);
        }
Exemple #4
0
        public DtoTblImage(TblImage image, HttpStatusCode statusEffect)
        {
            id     = image.id;
            Image  = image.Image;
            Status = image.Status;

            StatusEffect = statusEffect;
        }
Exemple #5
0
        public string uploadImageVariant(int id, HttpPostedFileBase imageVariant)
        {
            string strMessage = "upload0";

            try
            {
                if (imageVariant != null)
                {
                    if (imageVariant.ContentLength / 1024 / 1024 > 1)
                    {
                        strMessage = "upload2";
                    }
                    else if (imageVariant.ContentLength > 0)
                    {
                        VariantService variantService = new VariantService();
                        Variant        variant        = variantService.GetByPrimaryKey(id);
                        if (variant != null)
                        {
                            string folder = Server.MapPath("~/assets/uploads/products/") + variant.ProductID;
                            Directory.CreateDirectory(folder);

                            string path = Path.Combine(folder, Path.GetFileName(imageVariant.FileName));
                            imageVariant.SaveAs(path);

                            string strWhere = "";
                            strWhere = "ImageName like N'" + imageVariant.FileName + "' and ProductID = " + variant.ProductID;
                            TblImage imageOfProduct = imageService.SelectByWhere(strWhere).FirstOrDefault();
                            if (imageOfProduct == null || imageOfProduct.ImageID <= 0)
                            {
                                string imageUrl = "";
                                imageUrl = HttpContext.Request.Url.Authority == string.Empty ? Common.UrlHost : "http://" + HttpContext.Request.Url.Authority;
                                if (!imageUrl.EndsWith("/"))
                                {
                                    imageUrl += "/";
                                }
                                imageUrl += "assets/uploads/products/" + variant.ProductID + "/" + imageVariant.FileName;

                                TblImage image = new TblImage();
                                image.ImageName = imageVariant.FileName;
                                image.ImageUrl  = imageUrl;
                                image.ImageSize = imageVariant.ContentLength;
                                image.ProductID = variant.ProductID;
                                int imageID = imageService.Insert(image);

                                variant.ImageID = imageID;
                                variantService.Update(variant);
                                strMessage = "upload1";
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                LogService.WriteException(ex);
            }
            return(strMessage);
        }
Exemple #6
0
        public ActionResult Edit(TblImage TblImage, int id, FormCollection collection, int[] MutilMenu, int[] mutilManu)
        {
            if (ModelState.IsValid)
            {
                TblImage.IdCate = int.Parse(collection["drMenu"]);
                int idcate = int.Parse(collection["drMenu"]);
                db.Entry(TblImage).State = EntityState.Modified;
                db.SaveChanges();
                var ListImages = db.TblConnectImages.Where(p => p.IdImg == id).ToList();
                for (int i = 0; i < ListImages.Count; i++)
                {
                    db.TblConnectImages.Remove(ListImages[i]);
                    db.SaveChanges();
                }
                if (MutilMenu != null)
                {
                    foreach (var idCates in MutilMenu)
                    {
                        TblConnectImages tbllistimages = new TblConnectImages();
                        tbllistimages.IdCate = idCates;
                        tbllistimages.IdImg  = id;
                        db.TblConnectImages.Add(tbllistimages);
                        db.SaveChanges();
                    }
                }
                var listIdManu = db.TblConnectManuToImages.Where(p => p.IdImage == id).ToList();
                for (int i = 0; i < listIdManu.Count; i++)
                {
                    db.TblConnectManuToImages.Remove(listIdManu[i]);
                    db.SaveChanges();
                }
                if (mutilManu != null)
                {
                    foreach (var idMenu in mutilManu)
                    {
                        TblConnectManuToImages connectimage = new TblConnectManuToImages();
                        connectimage.IdManu  = idMenu;
                        connectimage.IdImage = id;
                        db.TblConnectManuToImages.Add(connectimage);
                        db.SaveChanges();
                    }
                }
                #region [Updatehistory]
                #endregion
                if (collection["btnSave"] != null)
                {
                    Session["Thongbao"] = "<div  class=\"alert alert-info alert1\">Bạn đã sửa  thành công !<button class=\"close\" data-dismiss=\"alert\">×</button></div>";

                    return(Redirect("/Imagesad/Index?idCate=" + idcate + ""));
                }
                if (collection["btnSaveCreate"] != null)
                {
                    Session["Thongbao"] = "<div  class=\"alert alert-info\">Bạn đã thêm thành công, mời bạn thêm mới !<button class=\"close\" data-dismiss=\"alert\">×</button></div>";
                    return(Redirect("/Imagesad/Create?id=" + idcate + ""));
                }
            }
            return(View(TblImage));
        }
Exemple #7
0
        public int uploadImageProduct(int id, HttpPostedFileBase fileProductDetail)
        {
            int intMessage = 0;

            try
            {
                if (fileProductDetail != null)
                {
                    if (fileProductDetail.ContentLength / 1024 / 1024 > 1)
                    {
                        intMessage = 2;
                    }
                    else if (fileProductDetail.ContentLength > 0)
                    {
                        try
                        {
                            string folder = Server.MapPath("~/assets/uploads/products/") + id;
                            Directory.CreateDirectory(folder);

                            string strWhere = "";
                            strWhere = "ImageName like N'" + fileProductDetail.FileName + "' and ProductID = " + id.ToString();
                            TblImage imageOfProduct = imageService.SelectByWhere(strWhere).FirstOrDefault();
                            if (imageOfProduct == null || imageOfProduct.ImageID <= 0)
                            {
                                string imageUrl = "";
                                imageUrl = HttpContext.Request.Url.Authority == string.Empty ? Common.UrlHost : "http://" + HttpContext.Request.Url.Authority;
                                if (!imageUrl.EndsWith("/"))
                                {
                                    imageUrl += "/";
                                }
                                imageUrl += "assets/uploads/products/" + id + "/" + fileProductDetail.FileName;

                                TblImage image = new TblImage();
                                image.ImageName = fileProductDetail.FileName;
                                image.ImageUrl  = imageUrl;
                                image.ImageSize = fileProductDetail.ContentLength;
                                image.ProductID = id;
                                imageService.Insert(image);
                            }

                            string path = Path.Combine(folder, Path.GetFileName(fileProductDetail.FileName));
                            fileProductDetail.SaveAs(path);
                            intMessage = 1;
                        }
                        catch (Exception ex)
                        {
                            intMessage = 0;
                            LogService.WriteException(ex);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                LogService.WriteException(ex);
            }
            return(intMessage);
        }
Exemple #8
0
        public ActionResult addImageFromUrl(int productID, string url)
        {
            int intMessage = 0;

            try
            {
                //save path to image in disk
                string pathImage = "";

                string folder = Server.MapPath("~/assets/uploads/products/") + productID;
                Directory.CreateDirectory(folder);

                if (!string.IsNullOrEmpty(url))
                {
                    //save name of file
                    string name = GetNameImageFromUrl(url);

                    if (!string.IsNullOrEmpty(name))
                    {
                        string strWhere = "";
                        strWhere = "ImageName like N'" + name + "' and ProductID = " + productID.ToString();
                        TblImage imageOfProduct = imageService.SelectByWhere(strWhere).FirstOrDefault();
                        if (imageOfProduct == null || imageOfProduct.ImageID <= 0)
                        {
                            pathImage = folder + "/" + name;
                            if (DownloadRemoteImageFile(url, pathImage))
                            {
                                //save path in web
                                string temp = "";
                                temp = HttpContext.Request.Url.Authority == string.Empty ? Common.UrlHost : "http://" + HttpContext.Request.Url.Authority;
                                if (!temp.EndsWith("/"))
                                {
                                    temp += "/";
                                }
                                temp += "assets/uploads/products/" + productID + "/" + name;
                                FileInfo fileInfo = new FileInfo(pathImage);

                                TblImage image = new TblImage();
                                image.ImageName = name;
                                image.ImageUrl  = temp;
                                image.ImageSize = fileInfo.Length;
                                image.ProductID = productID;
                                imageService.Insert(image);

                                intMessage = 1;
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                LogService.WriteException(ex);
            }
            return(RedirectToAction("detail", "products", new { id = productID, messageUpload = intMessage }));
        }
        public ActionResult Edit(int id = 0)
        {
            if ((Request.Cookies["Username"] == null))
            {
                return RedirectToAction("LoginIndex", "Login");
            }
            if (ClsCheckRole.CheckQuyen(8, 2, int.Parse(Request.Cookies["Username"].Values["UserID"])) == true)
            {
                TblImage TblImage = db.TblImage.Find(id);
                var menuModel = db.TblGroupProduct.Where(m => m.ParentId == null).OrderBy(m => m.Id).ToList();
                carlist.Clear();
                string strReturn = "---";
                foreach (var item in menuModel)
                {
                    carlist.Add(new SelectListItem { Text = item.Name, Value = item.Id.ToString() });
                    StringClass.DropDownListFor(item.Id, carlist, strReturn);
                    strReturn = "---";
                }
                var ListManu = db.TblConnectImages.Where(p => p.IdImg == id).ToList();
                List<int> mang = new List<int>();
                for (int i = 0; i < ListManu.Count; i++)
                {
                    mang.Add(int.Parse(ListManu[i].IdCate.ToString()));
                }
                ViewBag.MutilMenu = new MultiSelectList(carlist, "Value", "Text", mang);
                var Manufacture = db.TblManufactures.Where(m => m.Active == true).OrderBy(m => m.Ord).ToList();
                var listIdManu = db.TblConnectManuToImages.Where(p => p.IdImage == id).Select(p => p.IdManu).ToList();
                var lstmanu = new List<SelectListItem>();

                foreach (var item in Manufacture)
                {
                    lstmanu.Add(new SelectListItem { Text = item.Name, Value = item.Id.ToString() });
                }
                ViewBag.mutilManu = new MultiSelectList(lstmanu, "Value", "Text", listIdManu);
                int idCate = int.Parse(TblImage.IdCate.ToString());

                var menuModels = db.TblGroupImage.Where(m => m.Active == true).OrderBy(m => m.Ord).ToList();
                var lstMenus = new List<SelectListItem>();
                lstMenus.Clear();
                foreach (var menu in menuModels)
                {
                    lstMenus.Add(new SelectListItem { Text = menu.Name, Value = menu.Id.ToString() });
                }
                ViewBag.drMenu = new SelectList(lstMenus, "Value", "Text", idCate);
                if (TblImage == null)
                {
                    return HttpNotFound();
                }

                return View(TblImage);
            }
            else
            {
                return Redirect("/Users/Erro");
            }
        }
Exemple #10
0
        private int UploadImage(Variant variant)
        {
            if (variant == null || variant.imageVariant == null)
            {
                return(0);
            }
            int variantID = variant.VariantID, productID = variant.ProductID;
            HttpPostedFileBase file = variant.imageVariant;

            if (file.ContentLength / 1024 / 1024 > 1)
            {
                return(0);
            }
            else if (file.ContentLength > 0)
            {
                try
                {
                    string folder = Server.MapPath("~/assets/uploads/products/") + productID;
                    Directory.CreateDirectory(folder);

                    string strWhere = "";
                    strWhere = "ImageName like N'" + file.FileName + "' and ProductID = " + productID.ToString();
                    TblImage imageOfProduct = imageService.SelectByWhere(strWhere).FirstOrDefault();
                    if (imageOfProduct == null || imageOfProduct.ImageID <= 0)
                    {
                        string path = Path.Combine(folder, Path.GetFileName(file.FileName));
                        file.SaveAs(path);

                        string imageUrl = "";
                        imageUrl = HttpContext.Request.Url.Authority == string.Empty ? Common.UrlHost : "http://" + HttpContext.Request.Url.Authority;
                        if (!imageUrl.EndsWith("/"))
                        {
                            imageUrl += "/";
                        }
                        imageUrl += "assets/uploads/products/" + productID + "/" + file.FileName;

                        TblImage image = new TblImage();
                        image.ImageName = file.FileName;
                        image.ImageUrl  = imageUrl;
                        image.ImageSize = file.ContentLength;
                        image.ProductID = SNumber.ToNumber(productID);
                        int imageID = imageService.Insert(image);

                        return(imageID);
                    }
                }
                catch (Exception ex)
                {
                    LogService.WriteException(ex);
                    strErrorMessage += "Upload file thất bại<br/>";
                }
            }
            return(0);
        }
        public async Task <bool> UpdateImage(TblImage image, int logId)
        {
            List <object> imageAndLogId = new List <object>();

            imageAndLogId.Add(image);
            imageAndLogId.Add(logId);
            HttpResponseMessage httpResponseMessage = await _httpClient.PostAsJsonAsync("api/ImageCore/UpdateImage", imageAndLogId);

            bool ans = await httpResponseMessage.Content.ReadAsAsync <bool>();

            return(ans);
        }
Exemple #12
0
        /// <summary>
        /// get path to image first of product
        /// </summary>
        /// <param name="productID">id of product</param>
        /// <returns>path to image</returns>
        public static string GetPathImageFirstOfProduct(int productID)
        {
            IDbConnection connect = new SqlConnection(Common.ConnectString);
            string        path    = "";
            string        query   = "select * from TblImage where ProductID = " + productID.ToString();
            TblImage      image   = connect.Query <TblImage>(query).FirstOrDefault <TblImage>();

            if (image != null)
            {
                path = image.ImageUrl;
            }
            return(path);
        }
Exemple #13
0
 public int Insert(TblImage tblImage)
 {
     try
     {
         string query = string.Format("insert into TblImage(ImageName ,ImageUrl, ImageSize, ProductID) values (N'{0}',N'{1}',{2},{3}) SELECT @@IDENTITY", tblImage.ImageName, tblImage.ImageUrl, tblImage.ImageSize, tblImage.ProductID);
         return(connect.Query <int>(query).Single());
     }
     catch (Exception ex)
     {
         LogService.WriteException(ex);
         return(0);
     }
 }
        public ActionResult thankyou(int id)
        {
            try
            {
                TblOrder order = orderService.GetByPrimaryKey(id);
                if (order == null)
                {
                    return(RedirectToAction("index", "cart"));
                }

                List <LineItem> lineItems = lineItemService.GetByOrderID(order.OrderID);
                foreach (var item in lineItems)
                {
                    if (item.VariantName == "Default Title")
                    {
                        var thumb = ImageService.GetPathImageFirstOfProduct(item.ProductID);
                        item.ImageUrl = thumb;
                    }
                    else
                    {
                        Variant variant = variantService.GetByPrimaryKey(item.VariantID);
                        if (variant != null)
                        {
                            TblImage image = imageService.GetByPrimaryKey(variant.ImageID);
                            if (image != null)
                            {
                                item.ImageUrl = image.ImageUrl;
                            }
                        }
                    }
                }

                ThankyouViewModel thankyouViewModel = new ThankyouViewModel();
                thankyouViewModel.CustomerEmail     = order.CustomerEmail;
                thankyouViewModel.LineItems         = lineItems;
                thankyouViewModel.ShippingAddressID = order.ShippingAddressID;
                thankyouViewModel.ShippingAddress   = shippingAddressService.GetByPrimaryKey(thankyouViewModel.ShippingAddressID == null ? 0 : thankyouViewModel.ShippingAddressID.Value);
                thankyouViewModel.BillingAddresID   = order.BillingAddressID;
                thankyouViewModel.BillingAddress    = billingAddressService.GetByPrimaryKey(thankyouViewModel.BillingAddresID == null ? 0 : thankyouViewModel.BillingAddresID.Value);
                thankyouViewModel.TotalSubPrice     = order.TotalCount;
                thankyouViewModel.TotalShipping     = order.TotalShipping;
                thankyouViewModel.TotalPrice        = order.TotalCount + order.TotalShipping;
                return(View(thankyouViewModel));
            }
            catch (Exception ex)
            {
                LogService.WriteException(ex);
                throw;
            }
        }
Exemple #15
0
 public TblImage GetByPrimaryKey(int?imageID)
 {
     try
     {
         if (imageID != null)
         {
             string   query    = "select * from TblImage where ImageID = " + imageID;
             TblImage TblImage = connect.Query <TblImage>(query).FirstOrDefault <TblImage>();
             return(TblImage);
         }
     }
     catch (Exception ex)
     {
         LogService.WriteException(ex);
     }
     return(null);
 }
        public IHttpActionResult AddImage(TblImage image)
        {
            var task = Task.Run(() => new ImageService().AddImage(image));

            if (task.Wait(TimeSpan.FromSeconds(10)))
            {
                if (task.Result.id != -1)
                {
                    return(Ok(new DtoTblImage(task.Result, HttpStatusCode.OK)));
                }
                else
                {
                    return(Conflict());
                }
            }
            return(StatusCode(HttpStatusCode.RequestTimeout));
        }
Exemple #17
0
 public ActionResult DeleteImages(int id)
 {
     if (ClsCheckRole.CheckQuyen(9, 3, int.Parse(Request.Cookies["Username"].Values["UserID"])) == true)
     {
         TblImage TblImage = db.TblImage.Find(id);
         var      result   = string.Empty;
         db.TblImage.Remove(TblImage);
         db.SaveChanges();
         result = "Bạn đã xóa thành công.";
         return(Json(new { result = result }));
     }
     else
     {
         var result = string.Empty;
         result = "Bạn không có quyền thay đổi tính năng này";
         return(Json(new { result = result }));
     }
 }
Exemple #18
0
        public ActionResult Create(TblImage TblImage, FormCollection collection, int[] MutilMenu, int[] mutilManu)
        {
            int idCate = int.Parse(collection["drMenu"]);

            TblImage.IdCate = idCate;
            db.TblImage.Add(TblImage);
            db.SaveChanges();
            var ListManu = db.TblImage.OrderByDescending(p => p.Id).Take(1).ToList();
            int idimg    = int.Parse(ListManu[0].Id.ToString());

            if (MutilMenu != null)
            {
                foreach (var idMenu in MutilMenu)
                {
                    TblConnectImages TblConnectImages = new TblConnectImages();
                    TblConnectImages.IdCate = idMenu;
                    TblConnectImages.IdImg  = idimg;
                    db.TblConnectImages.Add(TblConnectImages);
                    db.SaveChanges();
                }
            }
            if (mutilManu != null)
            {
                foreach (var idMenu in mutilManu)
                {
                    TblConnectManuToImages connectimage = new TblConnectManuToImages();
                    connectimage.IdManu  = idMenu;
                    connectimage.IdImage = idimg;
                    db.TblConnectManuToImages.Add(connectimage);
                    db.SaveChanges();
                }
            }
            if (collection["btnSave"] != null)
            {
                Session["Thongbao"] = "<div  class=\"alert alert-info alert1\">Bạn đã thêm thành công !<button class=\"close\" data-dismiss=\"alert\">×</button></div>";
                return(Redirect("/Imagesad/Index?idCate=" + idCate + ""));
            }
            if (collection["btnSaveCreate"] != null)
            {
                Session["Thongbao"] = "<div  class=\"alert alert-info\">Bạn đã thêm thành công, mời bạn thêm mới !<button class=\"close\" data-dismiss=\"alert\">×</button></div>";
                return(Redirect("/Imagesad/Create?id=" + idCate + ""));
            }
            return(Redirect("Index"));
        }
        public IHttpActionResult UpdateImage(List <object> imageLogId)
        {
            TblImage image = JsonConvert.DeserializeObject <TblImage>(imageLogId[0].ToString());
            int      logId = JsonConvert.DeserializeObject <int>(imageLogId[1].ToString());
            var      task  = Task.Run(() => new ImageService().UpdateImage(image, logId));

            if (task.Wait(TimeSpan.FromSeconds(10)))
            {
                if (task.Result)
                {
                    return(Ok(true));
                }
                else
                {
                    return(Conflict());
                }
            }
            return(StatusCode(HttpStatusCode.RequestTimeout));
        }
Exemple #20
0
 public virtual void DeleteImage(Guid id)
 {
     try
     {
         TblImage entity = new TblImage {
             ImageId = id
         };
         List <TblImageTag> imageTags = (from it in dbContext.TblImageTag
                                         where it.ImageId == id
                                         select it).ToList();
         foreach (TblImageTag imageTag in imageTags)
         {
             dbContext.TblImageTag.Remove(imageTag);
         }
         dbContext.TblImage.Remove(entity);
         this.dbContext.SaveChanges();
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Exemple #21
0
        public virtual Guid Insert(Image entity)
        {
            try
            {
                TblImage tblImage = new TblImage();
                tblImage.AlbumImage = entity.AlbumImage;
                tblImage.ImageAlt   = entity.ImageAlt;
                tblImage.ImageId    = entity.ImageId;
                tblImage.ImageName  = entity.ImageName;
                tblImage.ImageUrl   = entity.ImageUrl;
                tblImage.ImageId    = Guid.NewGuid();
                dbContext.TblImage.Add(tblImage);

                AddRemoveTags(tblImage.ImageId, entity.ImageTags);

                this.dbContext.SaveChanges();
                return(tblImage.ImageId);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
 public TblImage AddImage(TblImage image)
 {
     return((TblImage) new MainProvider().Add(image));
 }
 public bool UpdateImage(TblImage image, int logId)
 {
     return(new MainProvider().Update(image, logId));
 }
Exemple #24
0
 public bool UpdateImage(TblImage image, int logId)
 {
     return(new ImageRepo().UpdateImage(image, logId));
 }
Exemple #25
0
 public TblImage AddImage(TblImage image)
 {
     return(new ImageRepo().AddImage(image));
 }
        public ActionResult getLineItem(string variantChoiced, string query)
        {
            try
            {
                LineItemsOfOrder productVariantOfProduct = new LineItemsOfOrder();
                List <Product>   products = new List <Product>();
                if (string.IsNullOrEmpty(query))
                {
                    products = productService.GetAll();
                }
                else
                {
                    string where = string.Format("ProductName like N'%{0}%' or Tags like N'%{1}%' ", query, query);
                    where       += string.Format(" or ProductID in (select Product.ProductID from Product left join TblOption on Product.ProductID = TblOption.ProductID " +
                                                 " where OptionValue like N'%{0}%')", query);
                    products = productService.GetByWhere(where);
                }

                List <int> variantIDs = new List <int>();
                if (!string.IsNullOrEmpty(variantChoiced))
                {
                    variantChoiced = SString.RemoveElementAtBeginEnd(variantChoiced, ",");
                    string[] temp = variantChoiced.Split(',');
                    foreach (var item in temp)
                    {
                        variantIDs.Add(SNumber.ToNumber(item));
                    }
                }

                if (products != null && products.Count > 0)
                {
                    foreach (var item in products)
                    {
                        List <Variant> variants = variantService.GetByProductID(item.ProductID);
                        if (variants != null && variants.Count > 0)
                        {
                            if (variants.Count == 1 && variants[0].Option1 == "Default Title")
                            {
                                LineItem temp = new LineItem();
                                temp.VariantID  = variants[0].VariantID;
                                temp.SKU        = variants[0].VariantSKU;
                                temp.ProductID  = item.ProductID;
                                temp.ObjectName = item.ProductName;
                                temp.IsDefault  = true;
                                temp.Price      = SNumber.ToNumber(variants[0].VariantPrice);
                                temp.Quantity   = 1;

                                var thumb = ImageService.GetPathImageFirstOfProduct(item.ProductID);
                                temp.ImageUrl = thumb;
                                if (!variantIDs.Contains(temp.VariantID))
                                {
                                    temp.CanChoice = true;
                                }
                                else
                                {
                                    temp.CanChoice = false;
                                }
                                productVariantOfProduct.ProductVariants.Add(temp);
                            }
                            else
                            {
                                LineItem product = new LineItem();
                                product.VariantID  = 0;
                                product.ProductID  = item.ProductID;
                                product.ObjectName = item.ProductName;
                                product.IsDefault  = true;
                                product.Price      = -1;
                                product.CanChoice  = false;
                                product.Quantity   = 1;
                                var thumb = ImageService.GetPathImageFirstOfProduct(item.ProductID);
                                product.ImageUrl = thumb;
                                productVariantOfProduct.ProductVariants.Add(product);

                                for (int i = 0; i < variants.Count; i++)
                                {
                                    LineItem temp = new LineItem();
                                    temp.ProductID  = item.ProductID;
                                    temp.VariantID  = variants[i].VariantID;
                                    temp.ObjectName = variants[i].VariantTittle;
                                    temp.SKU        = variants[i].VariantSKU;
                                    temp.IsDefault  = false;
                                    temp.Price      = SNumber.ToNumber(variants[i].VariantPrice);
                                    temp.Quantity   = 1;
                                    if (!variantIDs.Contains(temp.VariantID))
                                    {
                                        temp.CanChoice = true;
                                    }
                                    else
                                    {
                                        temp.CanChoice = false;
                                    }

                                    TblImage image = imageService.GetByPrimaryKey(variants[i].ImageID);
                                    if (image != null)
                                    {
                                        temp.ImageUrl = image.ImageUrl;
                                    }
                                    productVariantOfProduct.ProductVariants.Add(temp);
                                }
                            }
                        }
                    }
                }
                return(View(productVariantOfProduct));
            }
            catch (Exception ex)
            {
                LogService.WriteException(ex);
                return(null);
            }
        }
Exemple #27
0
        public ActionResult detail(int id, string strMessage = "")
        {
            try
            {
                string strError = "", strSuccess = "";
                if (!string.IsNullOrEmpty(strMessage))
                {
                    if (strMessage.Equals("bill1"))
                    {
                        strSuccess = "Xác nhận thanh toán thành công";
                    }
                    else if (strMessage.Equals("bill0"))
                    {
                        strError = "Xác nhận thanh toán thất bại";
                    }
                    else if (strMessage.Equals("delivery1"))
                    {
                        strSuccess = "Cập nhật thông tin giao hàng thành công";
                    }
                    else if (strMessage.Equals("delivery0"))
                    {
                        strError = "Cập nhật thông tin giao hàng thất bại";
                    }
                    else if (strMessage.Equals("update1"))
                    {
                        strSuccess = "Cập nhật thông tin đơn hàng thành công";
                    }
                    else if (strMessage.Equals("update0"))
                    {
                        strError = "Cập nhật thông tin đơn hàng thất bại";
                    }
                    else if (strMessage.Equals("addShippingAddress1"))
                    {
                        strSuccess = "Thêm mới địa chỉ giao hàng thành công";
                    }
                    else if (strMessage.Equals("addShippingAddress0"))
                    {
                        strError = "Thêm mới địa chỉ giao hàng thất bại";
                    }
                    else if (strMessage.Equals("editShippingAddress1"))
                    {
                        strSuccess = "Sửa địa chỉ giao hàng thành công";
                    }
                    else if (strMessage.Equals("editShippingAddress0"))
                    {
                        strError = "Sửa địa chỉ giao hàng thất bại";
                    }
                    else if (strMessage.Equals("editEmail1"))
                    {
                        strSuccess = "Sửa điạ chỉ email của khách hàng thành công";
                    }
                    else if (strMessage.Equals("editEmail1"))
                    {
                        strError = "Sửa điạ chỉ email của khách hàng thất bại";
                    }
                }
                ViewBag.strSuccess = strSuccess;
                ViewBag.strError   = strError;

                TblOrder order = orderService.GetByPrimaryKey(id);
                if (order == null)
                {
                    return(RedirectToAction("", "orders", new { strMessage = "notExist" }));
                }
                order.OrderName = "#" + (Common.BaseNumberOrder + order.Number).ToString() + " " + SDateTime.ToDateTime(order.CreatedDateTime);

                DetailOrderModel detailOrderModel = new DetailOrderModel();
                detailOrderModel.OrderID        = order.OrderID;
                detailOrderModel.CustomerEmail  = order.CustomerEmail;
                detailOrderModel.CustomerID     = order.CustomerID;
                detailOrderModel.Customer       = customerService.GetByPrimaryKey(SNumber.ToNumber(order.CustomerID));
                detailOrderModel.BillingStatus  = order.BillingStatus;
                detailOrderModel.ShippingStatus = order.ShippingStatus;
                detailOrderModel.TotalCount     = order.TotalCount;
                detailOrderModel.OrderName      = order.OrderName;
                detailOrderModel.OrderNote      = order.OrderNote;
                detailOrderModel.Tags           = order.Tags;
                detailOrderModel.ListTag        = tagService.GetByTableNameID((int)Common.TableName.TblOrder);

                detailOrderModel.BillingAddressID = SNumber.ToNumber(order.BillingAddressID);
                detailOrderModel.BillingAddress   = billingAddressService.GetByPrimaryKey(SNumber.ToNumber(order.BillingAddressID));
                if (detailOrderModel.BillingAddress != null)
                {
                    detailOrderModel.BillingAddress.Countries = countryService.GetAll();
                }

                detailOrderModel.ShippingAddressID = SNumber.ToNumber(order.ShippingAddressID);
                detailOrderModel.ShippingAddress   = shippingAddressService.GetByPrimaryKey(SNumber.ToNumber(order.ShippingAddressID));
                if (detailOrderModel.ShippingAddress == null)
                {
                    detailOrderModel.ShippingAddress = new ShippingAddress();
                }
                detailOrderModel.ShippingAddress.Countries = countryService.GetAll();

                if (order.OrderID > 0)
                {
                    List <LineItem> lineItems = lineItemService.GetByOrderID(order.OrderID);
                    foreach (var item in lineItems)
                    {
                        if (item.VariantName == "Default Title")
                        {
                            var thumb = ImageService.GetPathImageFirstOfProduct(item.ProductID);
                            item.ImageUrl = thumb;
                        }
                        else
                        {
                            Variant variant = variantService.GetByPrimaryKey(item.VariantID);
                            if (variant != null)
                            {
                                TblImage image = imageService.GetByPrimaryKey(variant.ImageID);
                                if (image != null)
                                {
                                    item.ImageUrl = image.ImageUrl;
                                }
                            }
                        }

                        if (item.ShippingStatus == null)
                        {
                            detailOrderModel.LineItemsPending.Add(item);
                        }
                        else
                        {
                            detailOrderModel.LineItemsPaid.Add(item);
                        }
                    }
                }
                return(View(detailOrderModel));
            }
            catch (Exception ex)
            {
                LogService.WriteException(ex);
                return(RedirectToAction("", "orders", new { strMessage = "notExist" }));
            }
        }