Esempio n. 1
0
        /// <summary>
        /// Add new project to database
        /// </summary>
        /// <returns></returns>
        public bool AddProject(MessageModel.CreateProjectPostRequest newProject)
        {
            try
            {
                portal_Projects project = new portal_Projects()
                {
                    Name            = newProject.Name,
                    Region          = newProject.Region,
                    Address         = newProject.Address,
                    Investor        = newProject.Investor,
                    ProjectPackage  = newProject.ProjectPackage,
                    TotalInvestment = newProject.TotalInvestment,
                    Duration        = newProject.Duration,
                    ProgressStatus  = newProject.ProgressStatus,
                    Type            = newProject.Type,
                    CoverImageId    = newProject.CoverImageId,
                    SortOrder       = newProject.SortOrder,
                    Status          = newProject.Status,
                    Description     = newProject.Description,
                    Description2    = newProject.Description2
                };

                share_Images coverImage = imageRepository.GetByID(newProject.CoverImageId);
                project.share_Images.Add(coverImage);
                db.Insert(project);
                db.Save();
                return(true);
            }
            catch (Exception)
            {
                return(false);
            }
        }
Esempio n. 2
0
        /// <summary>
        /// update image information of project
        /// </summary>
        /// <param name="projectId">project id</param>
        /// <param name="image">image id</param>
        /// <param name="isCoverImage">is cover image of project or not</param>
        /// <param name="listImages">list images of project returned</param>
        /// <returns></returns>
        public bool UpdateProjectImage(int projectId, MessageModel.UpdateProjectImage imageInfor, bool isCoverImage)
        {
            try
            {
                share_Images image = imageRepository.GetByID(imageInfor.ImageId);
                image.ImageName = imageInfor.Name;
                image.Status    = imageInfor.IsActive ? (int)Define.Status.Active : (int)Define.Status.Deactive;


                portal_Projects project = db.GetProjectById(projectId);
                if (isCoverImage)
                {
                    project.CoverImage = image;
                }
                else
                {
                    if (project.CoverImageId == image.Id)
                    {
                        project.CoverImage = null;
                    }
                }
                imageRepository.Update(image);
                db.Update(project);
                db.Save();
                imageRepository.Save();

                return(true);
            }
            catch (Exception)
            {
                return(false);
            }
        }
Esempio n. 3
0
        public ActionResult UploadImage(IEnumerable <HttpPostedFileBase> files, int productId)
        {
            if (files != null)
            {
                foreach (HttpPostedFileBase file in files)
                {
                    if (file.ContentLength > 0)
                    {
                        string largeFileName = null;
                        bool   isSuccess     = UploadProductImages(file, out largeFileName);
                        if (isSuccess)
                        {
                            share_Images largeImage = new share_Images
                            {
                                ImageName = largeFileName,
                                ImagePath = Path.Combine(ImageUpload.LoadPath, largeFileName)
                            };

                            service.AddImageForProduct(productId, largeImage);
                        }
                        else
                        {
                            // use imageResult.ErrorMessage to show the error
                            ViewBag.Error = "Upload product image fail";
                        }
                    }
                }
            }
            return(ListImageProduct(productId));
        }
Esempio n. 4
0
        /// <summary>
        /// Add new product to database
        /// </summary>
        /// <returns></returns>
        public bool AddProduct(CreateProductPostRequest newProduct)
        {
            try
            {
                ecom_Products product = new ecom_Products()
                {
                    ProductCode  = newProduct.ProductCode != null?newProduct.ProductCode:"",
                    Name         = newProduct.Name,
                    Price        = newProduct.Price,
                    Quantity     = newProduct.Quantity,
                    Unit         = newProduct.Unit,
                    BrandId      = newProduct.BrandId,
                    CoverImageId = newProduct.CoverImageId,
                    Description  = newProduct.Description,
                    Description2 = newProduct.Description2,
                    //Tags = newProduct.Tags,
                    Tags              = "",
                    IsNewProduct      = newProduct.IsNewProduct,
                    IsBestSellProduct = newProduct.IsBestSellProduct,
                    SortOrder         = newProduct.SortOrder,
                    Status            = newProduct.Status
                };

                share_Images coverImage = imageRepository.GetByID(newProduct.CoverImageId);
                product.share_Images.Add(coverImage);
                db.Insert(product);
                db.Save();
                return(true);
            }
            catch (Exception)
            {
                return(false);
            }
        }
Esempio n. 5
0
        public ActionResult Create(CreateProductPostRequest productRequest)
        {
            productRequest.CreateBy = User.Identity.GetUserName();
            if (User.IsInRole("Administrator"))
            {
                productRequest.Status = (int)Define.Status.Active;
            }
            else
            {
                productRequest.Status = (int)Define.Status.WaitingCreate;
            }
            if (ModelState.IsValid)
            {
                var file = Request.Files["coverImage"];
                //HttpPostedFileBase file = coverImage;
                if (file != null && file.ContentLength > 0)
                {
                    if (file.ContentLength > 0)
                    {
                        // width + height will force size, care for distortion
                        //Exmaple: ImageUpload imageUpload = new ImageUpload { Width = 800, Height = 700 };

                        // height will increase the width proportionally
                        //Example: ImageUpload imageUpload = new ImageUpload { Height= 600 };

                        // width will increase the height proportionally
                        ImageUpload imageUpload = new ImageUpload {
                            Width = 600
                        };

                        // rename, resize, and upload
                        //return object that contains {bool Success,string ErrorMessage,string ImageName}
                        ImageResult imageResult = imageUpload.RenameUploadFile(file);
                        if (imageResult.Success)
                        {
                            // Add new image to database
                            var photo = new share_Images
                            {
                                ImageName = imageResult.ImageName,
                                ImagePath = Path.Combine(ImageUpload.LoadPath, imageResult.ImageName)
                            };
                            var imageId = service.AddImage(photo);
                            // Add product
                            productRequest.CoverImageId = imageId;
                            productRequest.CreateBy     = User.Identity.GetUserName();
                            service.AddProduct(productRequest);
                            return(RedirectToAction("Index"));
                        }
                        else
                        {
                            // use imageResult.ErrorMessage to show the error
                            ViewBag.Error = imageResult.ErrorMessage;
                        }
                    }
                }
            }
            PopulateStatusDropDownList();
            ViewBag.BrandId = PopulateListBrand(productRequest.BrandId);
            return(View("Create1", productRequest));
        }
Esempio n. 6
0
        public ActionResult Create(CMSNewsView model, HttpPostedFileBase uploadFile)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    if (User.IsInRole("Administrator"))
                    {
                        model.Status = (int)OnlineStore.Infractructure.Utility.Define.Status.Active;
                    }
                    else
                    {
                        model.Status = (int)OnlineStore.Infractructure.Utility.Define.Status.WaitingCreate;
                    }
                    if (uploadFile != null && uploadFile.ContentLength > 0)
                    {
                        ImageUpload imageUpload = new ImageUpload {
                            IsScale = false, SavePath = ImageUpload.LoadPathCMSNews
                        };
                        ImageResult imageResult = imageUpload.RenameUploadFile(uploadFile);

                        if (imageResult.Success)
                        {
                            // Add new image to database
                            var photo = new share_Images
                            {
                                ImageName = imageResult.ImageName,
                                ImagePath = imageResult.ImagePath
                            };
                            var imageId = _productService.AddImage(photo);
                            if (imageId != null)
                            {
                                // Add banner
                                model.CoverImageId = imageId.Value;
                            }
                        }
                        else
                        {
                            ViewBag.Error = imageResult.ErrorMessage;
                        }
                    }

                    _cmsNewsService.AddCMSNews(model);

                    return(RedirectToAction("Index"));
                }
                catch (Exception ex)
                {
                    ModelState.AddModelError("", ex.Message);
                }
            }

            ViewBag.AvailableCategories = PrepareAllCategoriesModel();
            return(View(model));
        }
Esempio n. 7
0
        public static ImageProjectViewModel ConvertToImageProjectViewModel(this share_Images image)
        {
            ImageProjectViewModel imageViewModel = new ImageProjectViewModel()
            {
                Id        = image.Id,
                ImageName = image.ImageName,
                ImagePath = image.ImagePath,
                IsActive  = image.Status == (int)Define.Status.Active ? true : false
            };

            return(imageViewModel);
        }
Esempio n. 8
0
        public ActionResult Create(CreateProjectPostRequest projectRequest)
        {
            if (ModelState.IsValid)
            {
                var file = Request.Files["coverImage"];
                if (file != null && file.ContentLength > 0)
                {
                    if (file.ContentLength > 0)
                    {
                        // width + height will force size, care for distortion
                        //Exmaple: ImageUpload imageUpload = new ImageUpload { Width = 800, Height = 700 };

                        // height will increase the width proportionally
                        //Example: ImageUpload imageUpload = new ImageUpload { Height= 600 };

                        // width will increase the height proportionally
                        ImageUpload imageUpload = new ImageUpload {
                            Width = 600
                        };

                        // rename, resize, and upload
                        //return object that contains {bool Success,string ErrorMessage,string ImageName}
                        ImageResult imageResult = imageUpload.RenameUploadFile(file);
                        if (imageResult.Success)
                        {
                            // Add new image to database
                            var photo = new share_Images
                            {
                                ImageName = imageResult.ImageName,
                                ImagePath = Path.Combine(ImageUpload.LoadPath, imageResult.ImageName)
                            };
                            var imageId = service.AddImage(photo);
                            // Add product
                            projectRequest.CoverImageId = imageId;
                            service.AddProject(projectRequest);
                            return(RedirectToAction("Index"));
                        }
                        else
                        {
                            // use imageResult.ErrorMessage to show the error
                            ViewBag.Error = imageResult.ErrorMessage;
                        }
                    }
                }
            }
            PopulateProjectTypeDropDownList();
            PopulateRegionDropDownList();
            PopulateProgressStatusDropDownList();
            PopulateStatusDropDownList();
            return(View(projectRequest));
        }
Esempio n. 9
0
 /// <summary>
 /// Add new image to database
 /// </summary>
 /// <param name="image"></param>
 /// <returns></returns>
 public Nullable <int> AddImage(share_Images image)
 {
     try
     {
         image.Status = (int)Define.Status.Active;
         imageRepository.Insert(image);
         imageRepository.Save();
         return(image.Id);
     }
     catch (Exception)
     {
         return(null);
     }
 }
Esempio n. 10
0
        /// <summary>
        /// Add image for exist product
        /// </summary>
        /// <param name="IdProduct">product id</param>
        /// <param name="photo">new image</param>
        /// <param name="listImages"> return list image after adding finish</param>
        /// <returns>return true if action is success or false action is fail</returns>
        public bool AddImageForProduct(int IdProduct, share_Images photo)
        {
            ecom_Products product = db.GetProductById(IdProduct);

            if (product == null)
            {
                return(false);
            }
            else
            {
                product.share_Images.Add(photo);
                db.Save();
                return(true);
            }
        }
Esempio n. 11
0
        public ActionResult Edit(CMSNewsView model, HttpPostedFileBase uploadFile)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    if (uploadFile != null && uploadFile.ContentLength > 0)
                    {
                        ImageUpload imageUpload = new ImageUpload {
                            IsScale = false, SavePath = ImageUpload.LoadPathCMSNews
                        };
                        ImageResult imageResult = imageUpload.RenameUploadFile(uploadFile);

                        if (imageResult.Success)
                        {
                            // Add new image to database
                            var photo = new share_Images
                            {
                                ImageName = imageResult.ImageName,
                                ImagePath = imageResult.ImagePath
                            };
                            //var imageId = _productService.AddImage(photo);
                            //if (imageId != null)
                            //{
                            //    // Add banner
                            //    model.CoverImageId = imageId.Value;
                            //}
                        }
                        else
                        {
                            ViewBag.Error = imageResult.ErrorMessage;
                        }
                    }

                    _cmsNewsService.EditCMSNews(model);

                    return(RedirectToAction("Index"));
                }
                catch (Exception ex)
                {
                    ModelState.AddModelError("", ex.Message);
                }
            }

            ViewBag.AvailableCategories = PrepareAllCategoriesModel(model.Id);
            PopulateStatusDropDownList((Portal.Infractructure.Utility.Define.Status)model.Status);
            return(View(model));
        }
Esempio n. 12
0
        public ActionResult Create(CreateProductPostRequest productRequest)
        {
            if (ModelState.IsValid)
            {
                var file = Request.Files["coverImage"];
                if (file != null && file.ContentLength > 0)
                {
                    if (file.ContentLength > 0)
                    {
                        string largeFileName = null;
                        bool   isSuccess     = UploadProductImages(file, out largeFileName);

                        if (isSuccess)
                        {
                            share_Images largeImage = new share_Images
                            {
                                ImageName = largeFileName,
                                ImagePath = Path.Combine(ImageUpload.LargeImagePath, largeFileName)
                            };

                            var imageId = service.AddImage(largeImage);
                            // Add product
                            productRequest.CoverImageId = imageId;
                            bool isAddSuccess = service.AddProduct(productRequest);
                            if (isAddSuccess)
                            {
                                return(RedirectToAction("Index"));
                            }
                            else
                            {
                                ViewBag.Error = "Upload product image fail!";
                            }
                        }
                        else
                        {
                            // use imageResult.ErrorMessage to show the error
                            ViewBag.Error = "Create product fail!";
                        }
                    }
                }
            }
            PopulateStatusDropDownList();
            ViewBag.BrandId = PopulateListBrand(productRequest.BrandId);
            return(View(productRequest));
        }
Esempio n. 13
0
        public ActionResult Edit(BannerViewModel model, HttpPostedFileBase uploadFile)
        {
            if (ModelState.IsValid)
            {
                if (uploadFile != null && uploadFile.ContentLength > 0)
                {
                    ImageUpload imageUpload = new ImageUpload {
                        IsScale = false, SavePath = ImageUpload.LoadPathBanners
                    };
                    ImageResult imageResult = imageUpload.RenameUploadFile(uploadFile);

                    if (imageResult.Success)
                    {
                        // Add new image to database
                        var photo = new share_Images
                        {
                            ImageName = imageResult.ImageName,
                            ImagePath = imageResult.ImagePath
                        };
                        //var imageId = _productService.AddImage(photo);
                        //if (imageId != null)
                        //{
                        //    // Add banner
                        //    model.ImageId = imageId.Value;
                        //}
                    }
                    else
                    {
                        ViewBag.Error = imageResult.ErrorMessage;
                    }
                }

                _bannerService.EditBanner(model);
                return(RedirectToAction("Index"));
            }

            PopulateBannerTypesDropDownList((Portal.Infractructure.Utility.Define.BannerTypes)model.Type);
            PopulateStatusDropDownList((Portal.Infractructure.Utility.Define.Status)model.Status);
            return(View(model));
        }
Esempio n. 14
0
 /// <summary>
 /// Delete image in product
 /// </summary>
 /// <param name="productId">product id</param>
 /// <param name="imageId">id of image need to delete</param>
 /// <param name="listImages">list images of product after do action</param>
 /// <param name="imagePath">path of deteled image(using for delete image in folder)</param>
 /// <returns>return true if action is success or false if action is fail</returns>
 public bool DeleteImage(int productId, int imageId, out share_Images deleteImages)
 {
     try
     {
         ecom_Products product = GetProductById(productId);
         share_Images  image   = product.share_Images.Where(i => i.Id == imageId).SingleOrDefault();
         deleteImages = image;
         //Delete image in product
         product.share_Images.Remove(image);
         db.Save();
         // Delete image in table share_images
         var deleteImage = imageRepository.GetByID(imageId);
         imageRepository.Delete(deleteImage);
         imageRepository.Save();
         return(true);
     }
     catch (Exception)
     {
         deleteImages = null;
         return(false);
     }
 }
Esempio n. 15
0
        public ActionResult Create(BannerViewModel model, HttpPostedFileBase uploadFile)
        {
            if (ModelState.IsValid)
            {
                if (uploadFile != null && uploadFile.ContentLength > 0)
                {
                    ImageUpload imageUpload = new ImageUpload {
                        IsScale = false, SavePath = ImageUpload.LoadPathBanners
                    };
                    ImageResult imageResult = imageUpload.RenameUploadFile(uploadFile);

                    if (imageResult.Success)
                    {
                        // Add new image to database
                        var photo = new share_Images
                        {
                            ImageName = imageResult.ImageName,
                            ImagePath = imageResult.ImagePath
                        };
                        var imageId = _productService.AddImage(photo);
                        if (imageId != null)
                        {
                            // Add banner
                            model.ImageId = imageId.Value;
                            _bannerService.AddBanner(model);
                            return(RedirectToAction("Index"));
                        }
                    }
                    else
                    {
                        ViewBag.Error = imageResult.ErrorMessage;
                    }
                }
            }

            PopulateBannerTypesDropDownList();
            return(View(model));
        }
Esempio n. 16
0
        /// <summary>
        /// update image information of product
        /// </summary>
        /// <param name="productId">product id</param>
        /// <param name="image">image id</param>
        /// <param name="isCoverImage">is cover image of product or not</param>
        /// <param name="listImages">list images of product returned</param>
        /// <returns></returns>
        public bool UpdateProductImage(int productId, OnlineStore.Service.Messaging.UpdateProductImage imageInfor, bool isCoverImage)
        {
            try
            {
                share_Images image = imageRepository.GetByID(imageInfor.ImageId);
                image.ImageName = imageInfor.Name;
                image.Status    = imageInfor.IsActive ? (int)Define.Status.Active : (int)Define.Status.Deactive;


                ecom_Products product = db.GetProductById(productId);
                if (isCoverImage)
                {
                    //product.CoverImageId = image.Id;
                    product.CoverImage = image;
                }
                else
                {
                    if (product.CoverImageId == image.Id)
                    {
                        //product.CoverImageId = null;
                        product.CoverImage = null;
                    }
                }
                imageRepository.Update(image);
                db.Update(product);
                db.Save();
                imageRepository.Save();
                RefreshAll();

                return(true);
            }
            catch (Exception)
            {
                return(false);
            }
        }
        public ActionResult UploadImage(IEnumerable<HttpPostedFileBase> files, int? IdProduct)
        {

            if (IdProduct == null)
            {
                return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
            }
            product_Products product_Products = db.product_Products
               .Include(i => i.product_Categories)
               .Include(i => i.share_Images)
               .Where(i => i.ID == IdProduct)
               .Single();
            if (files != null)
            {
                foreach (var file in files)
                {

                    if (file.ContentLength > 0)
                    {
                        // width + height will force size, care for distortion
                        //Exmaple: ImageUpload imageUpload = new ImageUpload { Width = 800, Height = 700 };

                        // height will increase the width proportionally
                        //Example: ImageUpload imageUpload = new ImageUpload { Height= 600 };

                        // width will increase the height proportionally
                        ImageUpload imageUpload = new ImageUpload { Width = 600 };

                        // rename, resize, and upload
                        //return object that contains {bool Success,string ErrorMessage,string ImageName}
                        ImageResult imageResult = imageUpload.RenameUploadFile(file);
                        if (imageResult.Success)
                        {
                            //TODO: write the filename to the db
                            var photo = new share_Images
                            {
                                ImageName = imageResult.ImageName,
                                ImagePath = Path.Combine(ImageUpload.LoadPath, imageResult.ImageName)
                            };
                            if (product_Products.share_Images == null)
                            {
                                product_Products.share_Images = new List<share_Images>();
                            }
                            product_Products.share_Images.Add(photo);
                            if (product_Products.share_Images.Count() > 0)
                            {
                                product_Products.CoverImageID = product_Products.share_Images.ElementAt(0).ID;
                            }

                        }
                        else
                        {
                            // use imageResult.ErrorMessage to show the error
                            ViewBag.Error = imageResult.ErrorMessage;
                        }
                    }

                }
                db.SaveChanges();
            }
            LoadListImageProductPartialViewModels listImageViewModels = new LoadListImageProductPartialViewModels()
            {
                ProductId = product_Products.ID,
                Images = product_Products.share_Images
            };
            return PartialView("LoadListImageProduct", listImageViewModels);
        }
Esempio n. 18
0
 /// <summary>
 /// Add new product to database
 /// </summary>
 /// <returns></returns>
 public bool AddProduct(CreateProductPostRequest newProduct)
 {
     try
     {
         ecom_Products product = new ecom_Products()
         {
             ProductCode       = newProduct.ProductCode,
             Name              = newProduct.Name,
             Price             = newProduct.Price,
             Quantity          = newProduct.Quantity,
             Unit              = newProduct.Unit,
             BrandId           = newProduct.BrandId,
             CoverImageId      = newProduct.CoverImageId,
             Description       = newProduct.Description,
             Description2      = newProduct.Description2,
             Tags              = newProduct.Tags,
             IsNewProduct      = newProduct.IsNewProduct,
             IsBestSellProduct = newProduct.IsBestSellProduct,
             SortOrder         = newProduct.SortOrder,
             Status            = newProduct.Status,
             CreateTy          = newProduct.CreateBy,
             CreatedDate       = DateTime.Now,
             TotalBuy          = 0
         };
         if (newProduct.CategoryId == null)
         {
             product.ecom_Categories = new List <ecom_Categories>();
         }
         else
         {
             var selectedCategories = new HashSet <int>(newProduct.CategoryId);
             var categoriesProduct  = new HashSet <int>(product.ecom_Categories.Select(c => c.Id));
             foreach (var category in categoryRepository.GetAllCategories())
             {
                 if (selectedCategories.Contains(category.Id))
                 {
                     if (!categoriesProduct.Contains(category.Id))
                     {
                         product.ecom_Categories.Add(category);
                     }
                 }
                 else
                 {
                     if (categoriesProduct.Contains(category.Id))
                     {
                         product.ecom_Categories.Remove(category);
                     }
                 }
             }
         }
         share_Images coverImage = imageRepository.GetByID(newProduct.CoverImageId);
         product.share_Images.Add(coverImage);
         db.Insert(product);
         db.Save();
         return(true);
     }
     catch (Exception)
     {
         return(false);
     }
 }
        public ActionResult Create([Bind(Include = "ProductCode,CategoryID,Title,Quantity,Unit,PriceOfUnit,CoverImageID,Description,Description2,TotalView,TotalBuy,Tags,IsNewProduct,IsBestSellProduct,SortOrder,Status,CreatedBy,CreatedDate,ModifiedBy,ModifiedDate")] product_Products product_Products, HttpPostedFileBase upload)
        {
            if (ModelState.IsValid)
            {
                HttpPostedFileBase file = upload;
                if (upload != null && upload.ContentLength > 0)
                {
                    if (file.ContentLength > 0)
                    {
                        // width + height will force size, care for distortion
                        //Exmaple: ImageUpload imageUpload = new ImageUpload { Width = 800, Height = 700 };

                        // height will increase the width proportionally
                        //Example: ImageUpload imageUpload = new ImageUpload { Height= 600 };

                        // width will increase the height proportionally
                        ImageUpload imageUpload = new ImageUpload { Width = 600 };

                        // rename, resize, and upload
                        //return object that contains {bool Success,string ErrorMessage,string ImageName}
                        ImageResult imageResult = imageUpload.RenameUploadFile(file);
                        if (imageResult.Success)
                        {
                            //TODO: write the filename to the db
                            var photo = new share_Images
                            {
                                ImageName = imageResult.ImageName,
                                ImagePath = Path.Combine(ImageUpload.LoadPath, imageResult.ImageName)
                            };
                            product_Products.share_Images = new List<share_Images>();
                            product_Products.share_Images.Add(photo);
                            if (product_Products.share_Images.Count() > 0)
                            {
                                product_Products.CoverImageID = product_Products.share_Images.ElementAt(0).ID;
                            }
                        }
                        else
                        {
                            // use imageResult.ErrorMessage to show the error
                            ViewBag.Error = imageResult.ErrorMessage;
                        }
                    }
                }

                product_Products.GUID = System.Guid.NewGuid();
                db.product_Products.Add(product_Products);
                db.SaveChanges();
                return RedirectToAction("Index");
            }
            PopulateStatusDropDownList(product_Products.Status);
            ViewBag.CategoryID = new SelectList(db.product_Categories, "ID", "Title", product_Products.CategoryID);
            return View(product_Products);
        }