public virtual async Task <ActionResult> Add(AddPostViewModel postModel)
        {
            if (!ModelState.IsValid)
            {
                ViewData["CategoriesSelectList"] = new SelectList(await _postCategoryService.GetAll(), "Id", "Name");

                return(View(postModel));
            }

            var post = new DomainClasses.Post
            {
                PostedByUserId = User.Identity.GetUserId <int>()
            };

            _mappingEngine.Map(postModel, post);

            if (postModel.Id.HasValue)
            {
                _postService.Edit(post);
                TempData["message"] = "پست مورد نظر با موفقیت ویرایش شد";
            }
            else
            {
                _postService.Add(post);
                TempData["message"] = "پست جدید با موفقیت در سیستم ثبت شد";
            }

            await _unitOfWork.SaveAllChangesAsync();


            if (postModel.Id.HasValue)
            {
                LuceneIndex.ClearLucenePostIndexRecord(postModel.Id.Value);
            }

            LuceneIndex.AddUpdateLuceneIndex(new LuceneSearchModel
            {
                PostId      = post.Id,
                Title       = post.Title,
                Image       = post.Image,
                Description = post.Body.RemoveHtmlTags(),
                Category    = await _postCategoryService.GetCategoryName(postModel.CategoryId.Value),
                SlugUrl     = post.SlugUrl
            });


            return(RedirectToAction(MVC.Post.Admin.ActionNames.Index));
        }
        public override async Task RunAsync()
        {
            if (this.IsShuttingDown || this.Pause)
            {
                return;
            }

            LuceneIndex.ClearLuceneIndex();

            var productService = IoC.Container.GetInstance <IProductService>();
            var postService    = IoC.Container.GetInstance <IPostService>();

            foreach (var product in await productService.GetAllForLuceneIndex())
            {
                LuceneIndex.ClearLuceneIndexRecord(product.Id);
                LuceneIndex.AddUpdateLuceneIndex(new LuceneSearchModel
                {
                    ProductId     = product.Id,
                    Title         = product.Title,
                    Image         = product.Image,
                    Description   = product.Description.RemoveHtmlTags(),
                    Category      = "کالا‌ها",
                    SlugUrl       = product.SlugUrl,
                    Price         = product.Price.ToString(CultureInfo.InvariantCulture),
                    ProductStatus = product.ProductStatus.ToString()
                });
            }

            foreach (var post in await postService.GetAllForLuceneIndex())
            {
                LuceneIndex.ClearLucenePostIndexRecord(post.Id);
                LuceneIndex.AddUpdateLuceneIndex(new LuceneSearchModel
                {
                    PostId      = post.Id,
                    Title       = post.Title,
                    Image       = post.Image,
                    Description = post.Description.RemoveHtmlTags(),
                    Category    = post.Category,
                    SlugUrl     = post.SlugUrl
                });
            }
        }
        public virtual async Task <ActionResult> ReIndex()
        {
            LuceneIndex.ClearLuceneIndex();

            var productService = IoC.Container.GetInstance <IProductService>();
            var postService    = IoC.Container.GetInstance <IPostService>();

            foreach (var product in await productService.GetAllForLuceneIndex())
            {
                LuceneIndex.ClearLuceneIndexRecord(product.Id);
                LuceneIndex.AddUpdateLuceneIndex(new LuceneSearchModel
                {
                    ProductId     = product.Id,
                    Title         = product.Title,
                    Image         = product.Image,
                    Description   = product.Description.RemoveHtmlTags(),
                    Category      = "کالا‌ها",
                    SlugUrl       = product.SlugUrl,
                    Price         = product.Price.ToString(CultureInfo.InvariantCulture),
                    ProductStatus = product.ProductStatus.ToString()
                });
            }

            foreach (var post in await postService.GetAllForLuceneIndex())
            {
                LuceneIndex.ClearLucenePostIndexRecord(post.Id);
                LuceneIndex.AddUpdateLuceneIndex(new LuceneSearchModel
                {
                    PostId      = post.Id,
                    Title       = post.Title,
                    Image       = post.Image,
                    Description = post.Description.RemoveHtmlTags(),
                    Category    = post.Category,
                    SlugUrl     = post.SlugUrl
                });
            }
            return(Content("ReIndexing Complete."));
        }
Beispiel #4
0
        public virtual async Task <ActionResult> AddProduct(AddProductViewModel productModel)
        {
            if (!ModelState.IsValid)
            {
                ViewData["CategoriesSelectList"] = new MultiSelectList(
                    (await _categoryService.GetAll())
                    .Union(productModel.Categories.Select(x => new Category {
                    Name = x
                }),
                           new ProductCategoryComparer()), "Name", "Name",
                    productModel.Categories);

                return(View(productModel));
            }

            if (productModel.Count <= 0)
            {
                productModel.Count         = 0;
                productModel.ProductStatus = ProductStatus.NotAvailable;;
            }

            var addedProductImages = productModel.Images
                                     .Where(image => image.Id == null)
                                     .Select(image => new { image.Url, image.Name, image.ThumbnailUrl })
                                     .ToList();

            var deletedProductImages = new List <ProductImage>();

            var product = new DomainClasses.Product();

            foreach (var productImage in productModel.Images.Where(image => image.Id == null))
            {
                productImage.Url          = Url.Content("~/UploadedFiles/ProductImages/" + Path.GetFileName(getFilePath(productImage.Name, Server.MapPath("~/UploadedFiles/ProductImages"))));
                productImage.ThumbnailUrl = Url.Content("~/UploadedFiles/ProductImages/Thumbs/" + Path.GetFileName(getFilePath(productImage.Name, Server.MapPath("~/UploadedFiles/ProductImages/Thumbs"))));
                productImage.DeleteUrl    = "";
            }

            _mappingEngine.Map(productModel, product);

            if (productModel.Id.HasValue)
            {
                deletedProductImages = (await _productService.EditProduct(product)).ToList();
                TempData["message"]  = "کالای مورد نظر با موفقیت ویرایش شد";
            }
            else
            {
                product.Title          = productModel.Name;
                product.PostedDate     = DateTime.Now;
                product.PostedByUserId = 1;
                await _productService.AddProduct(product);

                TempData["message"] = "کالای جدید با موفقیت ثبت شد";
            }

            await _unitOfWork.SaveAllChangesAsync();

            foreach (var productImage in addedProductImages)
            {
                var path      = getFilePath(productImage.Name, Server.MapPath("~/UploadedFiles/ProductImages"));
                var thumbPath = getFilePath(productImage.Name, Server.MapPath("~/UploadedFiles/ProductImages/Thumbs"));

                System.IO.File.Move(Server.MapPath("~/Content/tmp/" + Path.GetFileName(productImage.Url)), path);
                System.IO.File.Move(Server.MapPath("~/Content/tmp/" + Path.GetFileName(productImage.ThumbnailUrl)), thumbPath);
            }

            foreach (var productImage in deletedProductImages)
            {
                var path      = Server.MapPath("~/UploadedFiles/ProductImages/" + productImage.Name);
                var thumbPath = Server.MapPath("~/UploadedFiles/ProductImages/Thumbs/" + productImage.Name);
                System.IO.File.Delete(path);
                System.IO.File.Delete(thumbPath);
            }

            if (productModel.Id.HasValue)
            {
                LuceneIndex.ClearLuceneIndexRecord(productModel.Id.Value);
            }

            //Index the new product lucene.NET
            LuceneIndex.AddUpdateLuceneIndex(new LuceneSearchModel
            {
                ProductId     = product.Id,
                Description   = product.Body.RemoveHtmlTags(),
                Title         = product.Title,
                ProductStatus = product.ProductStatus.ToString(),
                Price         = product.Prices
                                .OrderByDescending(productPrice => productPrice.Date)
                                .Select(productPrice => productPrice.Price).
                                FirstOrDefault().
                                ToString(CultureInfo.InvariantCulture),
                Image = product.Images.OrderBy(image => image.Order)
                        .Select(image => image.ThumbnailUrl)
                        .FirstOrDefault(),
                SlugUrl  = product.SlugUrl,
                Category = "کالا‌ها"
            });


            return(RedirectToAction(MVC.Product.Admin.ActionNames.Index));
        }
Beispiel #5
0
        // Returns the dataset
        //Consider to substitute for resultset for better performance!

        /*"Overall, SqlCeResultSet-based data sources require less memory, have better performance,
         * but have fewer features than DataSet-based data sources.*/
        //http://msdn.microsoft.com/en-us/library/ms180730%28v=vs.90%29.aspx
        //http://www.lucenetutorial.com/techniques/indexing-databases.html

        private static void _createIndex(string sqlQuery)
        {
            //@"Data Source=RUMSCWS141\SQLEXPRESS;initial catalog=ArmMunicipal;User Id=armUser;Password=fhv123"))
            //ArmMunicipalМО
            using (SqlConnection sqlCon = new SqlConnection(_connectionString))
            {
                try
                {
                    _shouldClose = false;
                    sqlCon.Open();
                    SqlCommand sqlCmd = sqlCon.CreateCommand();
                    sqlCmd.CommandTimeout = 0;
                    sqlCmd.CommandText    = sqlQuery;
                    using (SqlDataReader reader = sqlCmd.ExecuteReader(CommandBehavior.CloseConnection))
                    {
                        //get data line by line with SqlDataReader
                        while (reader.Read())
                        {
                            try
                            {
                                //1, ru50.501.301,решение,Представительный орган муниципального образования,Совет депутатов сельского поселения Федоскинское,Об утверждении Порядка представления, рассмотрения,внешней проверки, отчета об исполнении бюджета сельского поселения Федоскинское и его утверждения ,26.03.2009 0:00:00
                                Console.WriteLine(_reportStartExtracting(reader));
                                //_reportStartExtracting(reader);
                                LuceneIndex.AddUpdateLuceneIndex(_extractRowToCriterion(reader));
                                Console.WriteLine("-----------EXTRACTING SUCCESSFUL--------------");
                                Function(1, _rowCount); //change from progresbar to write label without maxcount event
                            }
                            catch (TextExtractionException txtExtrEx)
                            {
                                Console.WriteLine(_reportErrorExtracting(reader));
                                var sb = new StringBuilder();

                                #region CatchInnerException

                                try
                                {
                                    sb.Append("ErrorString:@");
                                    sb.Append(_reportErrorExtracting(reader));
                                    sb.Append("@@");
                                    sb.Append("OuterException Message:@");
                                    sb.Append(txtExtrEx.Message);
                                    sb.Append("@@");
                                    if (!string.IsNullOrEmpty(txtExtrEx.InnerException.Message))
                                    {
                                        sb.Append("--InnerException Message:@");
                                        sb.Append("--" + txtExtrEx.InnerException.Message);
                                        sb.Append("@@");
                                    }
                                }
                                catch
                                {
                                }
                                try
                                {
                                    if (!string.IsNullOrEmpty(txtExtrEx.InnerException.InnerException.Message))
                                    {
                                        sb.Append("----InnerException Message:@");
                                        sb.Append("----" + txtExtrEx.InnerException.InnerException.Message);
                                        sb.Append("@@");
                                    }
                                }
                                catch
                                {
                                }
                                try
                                {
                                    if (
                                        !string.IsNullOrEmpty(
                                            txtExtrEx.InnerException.InnerException.InnerException.Message))
                                    {
                                        sb.Append("------InnerException Message:@");
                                        sb.Append("------"
                                                  + txtExtrEx.InnerException.InnerException.InnerException.Message);
                                    }
                                }
                                catch
                                {
                                }

                                #endregion

                                #region MessageBox

                                ////Add MessageBox with timer, here!
                                //sb.AppendFormat("Press YES to skip the extraction of ID {0} and continue. Press CANCEL to exit.", reader[0]);
                                //DialogResult result = MessageBox.Show(sb.ToString().Replace("@", Environment.NewLine), "Text Caption",
                                //    MessageBoxButtons.YesNo);

                                //if (result == DialogResult.Yes)
                                //{
                                //    continue;
                                //}
                                //else if (result == DialogResult.No)
                                //{
                                //    _shouldClose = true;
                                //    throw new Exception("TextExtractionException", txtExtrEx);
                                //}

                                #endregion

                                _shouldClose = false;
                            }
                        }
                    }
                }

                catch (SqlException sqlException)
                {
                    _shouldClose = true;
                    throw new Exception("SqlException", sqlException);
                }
                catch (Exception exception)
                {
                    _shouldClose = true;
                    throw new Exception("Exception", exception);
                }

                finally
                {
                    //bool should close yes? close
                    if (_shouldClose)
                    {
                        sqlCon.Close();
                    }
                }
            }
        }