Ejemplo n.º 1
0
 public ActionResult Edit(BlogFormModel blogToEdit, bool continueEditing)
 {
     if (ModelState.IsValid)
     {
         //Mapping to domain
         Blog blog = Mapper.Map <BlogFormModel, Blog>(blogToEdit);
         if (String.IsNullOrEmpty(blog.Slug))
         {
             blog.Slug = StringConvert.ConvertShortName(blog.Title);
         }
         _blogService.EditBlog(blog);
         return(continueEditing ? RedirectToAction("Edit", "Blog", new { blogId = blog.Id })
                          : RedirectToAction("Index", "Blog"));
     }
     else
     {
         blogToEdit.ListCategory = _blogCategoryService.GetBlogCategories().ToSelectListItems(-1);
         return(View("Edit", blogToEdit));
     }
 }
Ejemplo n.º 2
0
        public ActionResult TimKiemKhachSan(String term)
        {
            SetDefaultAttribute();
            ViewBag.tour = "DEAL KHÁCH SẠN";
            if (term == "" || term == null)
            {
                return(RedirectToAction("KhachSan", "Home"));
            }
            var model = new TourTrongNuocModel();

            term = term.ToLower();
            var slug = StringConvert.ConvertShortName(term);

            model.tourType      = "in";
            model.viewType      = "list";
            model.listTourInHot = _productService.GetTourInHot().ToList();
            model.totalPage     = 1;
            model.listTourIn    = _productService.GetAllProducts().Where(p => (p.Name.ToLower().Contains(term) || p.Slug.Contains(slug)) && p.ProductCategory.Name == "Khách sạn").ToList();
            return(View("KhachSan", model));
        }
Ejemplo n.º 3
0
 public ActionResult TimKiemTour(String term, String tour)
 {
     SetDefaultAttribute();
     if (tour == "Tour trong nước")
     {
         ViewBag.tour = "TRONG NƯỚC";
         if (term == "" || term == null)
         {
             return(RedirectToAction("TourTrongNuoc", "Home"));
         }
         var model = new TourTrongNuocModel();
         term = term.ToLower();
         var slug = StringConvert.ConvertShortName(term);
         model.tourType      = "in";
         model.viewType      = "list";
         model.listTourInHot = _productService.GetTourInHot().ToList();
         model.listTourInNew = _productService.GetTourInNew().ToList();
         model.totalPage     = 1;
         model.listTourIn    = _productService.GetAllProducts().Where(p => (p.Name.ToLower().Contains(term) || p.Slug.Contains(slug)) && p.ProductCategory.Name == tour).ToList();
         return(View("TourTrongNuoc", model));
     }
     else
     {
         ViewBag.tour = "NƯỚC NGOÀI";
         if (term == "" || term == null)
         {
             return(RedirectToAction("TourNuocNgoai", "Home"));
         }
         var model = new TourTrongNuocModel();
         term = term.ToLower();
         var slug = StringConvert.ConvertShortName(term);
         model.tourType      = "out";
         model.viewType      = "list";
         model.listTourInHot = _productService.GetHotelPopulaire().ToList();
         model.totalPage     = 1;
         model.listTourIn    = _productService.GetAllProducts().Where(p => (p.Name.ToLower().Contains(term) || p.Slug.Contains(slug)) && p.ProductCategory.Name == tour).ToList();
         return(View("TourTrongNuoc", model));
     }
 }
        public ActionResult SubmitProperty(submitPropertyModel model, string place = "mp")
        {
            var temp = _productService.GetProductById(model.Product.Id);

            temp.ProductCategoryMappings.FirstOrDefault().ProductCategoryId = model.CategoryId;
            try
            {
                temp.Slug = StringConvert.ConvertShortName(model.Product.Name) + "-" + model.Product.Id;
            }
            catch (Exception)
            {
                return(RedirectToAction("SubmitProperty", new { Id = temp.Id, place = place }));
            }
            temp.ColorId      = model.Product.ColorId;
            temp.CodeName     = model.Product.CodeName;
            temp.OldPrice     = model.CategoryId;
            temp.Content      = model.Product.Content;
            temp.Description  = model.Product.Description;
            temp.IsHomePage   = true;
            temp.IsNew        = model.Product.IsNew;
            temp.IsPublic     = model.Product.IsPublic;
            temp.Name         = model.Product.Name;
            temp.Deleted      = false;
            temp.OrginalPrice = model.Product.OrginalPrice;
            foreach (var item in model.Product.ProductAttributeMappings)
            {
                if (item.Value != null)
                {
                    temp.ProductAttributeMappings.Where(p => p.Id == item.Id).FirstOrDefault().Value = item.Value;
                }
                else
                {
                    temp.ProductAttributeMappings.Where(p => p.Id == item.Id).FirstOrDefault().Value = "0";
                }
            }

            temp.ProductAttributeMappings.Where(m => m.ProductAttributeId == 30).FirstOrDefault().Value = model.Product.ProductAttributeMappings.Where(p => p.ProductAttributeId == 30).FirstOrDefault().Value;
            temp.LastEditedTime = DateTime.Now;
            if (!temp.ProductPictureMappings.Any())
            {
                var pic = new Picture();
                pic.IsDeleted = false;
                pic.Url       = "/Images/vin_hom_tan_cang.jpg";
                _pictureService.CreatePicture(pic);
                ProductPictureMapping mapping = new ProductPictureMapping();
                mapping.ProductId = temp.Id;
                mapping.PictureId = pic.Id;
                temp.ProductPictureMappings.Add(mapping);
            }
            //foreach (var item in temp.ProductPictureMappings)
            //{
            //model.Product.ProductPictureMappings.Add(item);
            //}
            try
            {
                _productService.EditProduct(temp);
            }
            catch (Exception)
            {
                return(RedirectToAction("SubmitProperty", new { Id = temp.Id, place = place }));
            }
            if (place.Equals("wp"))
            {
                return(RedirectToAction("WaitingProperty"));
            }
            else if (place.Equals("mp"))
            {
                return(RedirectToAction("MyProperty"));
            }
            else if (place.Equals("fe"))
            {
                return(Redirect("/san-pham/" + temp.Slug));
            }
            else if (place.Equals("am"))
            {
                return(Redirect("/Admin/Product"));
            }
            else if (place != "")
            {
                return(Redirect(place));
            }
            return(RedirectToAction("MyProperty"));
        }
        public ActionResult Create(ProductFormModel newProduct, bool continueEditing)
        {
            if (ModelState.IsValid)
            {
                //Mapping to domain
                //Product product = Mapper.Map<ProductFormModel, Product>(newProduct.pro);
                Product product = newProduct.product;
                if (String.IsNullOrEmpty(product.Slug))
                {
                    product.Slug = StringConvert.ConvertShortName(product.Name);
                }

                //Create Product
                _productService.CreateProduct(product);
                product.Slug = product.Slug + "-" + product.Id;
                //if (newProduct.CategoryId != 0)
                //{
                //    ProductCategoryMapping obj = new ProductCategoryMapping();
                //    obj.ProductId = product.Id;
                //    obj.ProductCategoryId = newProduct.CategoryId;
                //    _ProductCategoryMappingService.CreateProductCategoryMapping(obj);
                //}
                if (newProduct.CategoryId != 0)
                {
                    ProductCategoryMapping obj = new ProductCategoryMapping();
                    obj.ProductId         = product.Id;
                    obj.ProductCategoryId = newProduct.CategoryId;
                    _ProductCategoryMappingService.CreateProductCategoryMapping(obj);
                }
                //Add ProductAttribute after product created
                product.ProductAttributeMappings = new Collection <ProductAttributeMapping>();
                var listAttributeId = _productAttributeService.GetProductAttributes().Select(p => p.Id);
                foreach (var id in listAttributeId)
                {
                    product.ProductAttributeMappings.Add(
                        new ProductAttributeMapping()
                    {
                        ProductAttributeId = id, ProductId = product.Id
                    });
                }
                //nhap thong tin nguoi tao
                var users = GetInfo();
                product.ProductAttributeMappings.Where(p => p.ProductAttributeId == 19).FirstOrDefault().Value = users.UserName;
                product.ProductAttributeMappings.Where(p => p.ProductAttributeId == 20).FirstOrDefault().Value = users.FirstName;
                product.ProductAttributeMappings.Where(p => p.ProductAttributeId == 21).FirstOrDefault().Value = users.PhoneNumber;
                product.ProductAttributeMappings.Where(p => p.ProductAttributeId == 22).FirstOrDefault().Value = users.Email;
                product.ProductAttributeMappings.Where(p => p.ProductAttributeId == 23).FirstOrDefault().Value = users.Skype;

                //Add Picture default for Labixa
                product.ProductPictureMappings = new Collection <ProductPictureMapping>();
                for (int i = 0; i < 6; i++)
                {
                    var  newPic = new Picture();
                    bool ismain = i == 0;
                    _pictureService.CreatePicture(newPic);
                    product.ProductPictureMappings.Add(
                        new ProductPictureMapping()
                    {
                        PictureId     = newPic.Id,
                        ProductId     = product.Id,
                        IsMainPicture = ismain,
                        DisplayOrder  = 0,
                    });
                }
                _productService.EditProduct(product);


                //create product relation

                //Save all after edit
                return(RedirectToAction("Index", "Product"));
            }
            else
            {
                Product          product = new Product();
                ProductFormModel model   = new ProductFormModel();

                model.product = product;
                return(View("Create", model));
            }
        }
Ejemplo n.º 6
0
        public ActionResult Create(ProductFormModel newProduct, bool continueEditing)
        {
            if (ModelState.IsValid)
            {
                //Mapping to domain
                Product product = Mapper.Map <ProductFormModel, Product>(newProduct);
                if (String.IsNullOrEmpty(product.Slug))
                {
                    product.Slug = StringConvert.ConvertShortName(product.Name);
                }

                //Create Product
                _productService.CreateProduct(product);

                //Add ProductAttribute after product created
                //product.ProductAttributeMappings = new Collection<ProductAttributeMapping>();
                //var listAttributeId = _productAttributeService.GetProductAttributes().Select(p => p.Id);
                //foreach (var id in listAttributeId)
                //{
                //    product.ProductAttributeMappings.Add(
                //        new ProductAttributeMapping() { ProductAttributeId = id, ProductId = product.Id });

                //}
                //Add Picture default for Labixa
                product.ProductPictureMappings = new Collection <ProductPictureMapping>();
                for (int i = 0; i < 4; i++)
                {
                    var  newPic = new Picture();
                    bool ismain = i == 0;
                    _pictureService.CreatePicture(newPic);
                    product.ProductPictureMappings.Add(
                        new ProductPictureMapping()
                    {
                        PictureId     = newPic.Id,
                        ProductId     = product.Id,
                        IsMainPicture = ismain,
                        DisplayOrder  = 0,
                    });
                }
                _productService.EditProduct(product);


                //create product relation
                #region
                ProductRelationship item2 = new ProductRelationship();
                for (int i = 0; i < 3; i++)
                {
                    ProductRelationship item = new ProductRelationship();
                    item.ProductId       = product.Id;
                    item.ProductRelateId = product.Id;
                    item.isAvailable     = true;
                    _productRelationShipService.CreateProductRelationship(item);
                }
                #endregion
                //Save all after edit
                return(continueEditing ? RedirectToAction("Edit", "Product", new { productId = product.Id })
                                : RedirectToAction("Index", "Product"));
            }
            else
            {
                var listProductCategory = _productCategoryService.GetProductCategories().ToSelectListItems(-1);
                newProduct.ListProductCategory = listProductCategory;
                return(View("Create", newProduct));
            }
        }