public ActionResult UpdateProduct(Product model)
 {
     if (ModelState.IsValid)
     {
         var       dao       = new ProductDAO();
         UserLogin userlogin = (UserLogin)Session["USER_SESSION"];
         model.ModifiedBy = userlogin.UserName;
         string metatitle = CastString.Cast(model.Name);
         model.MetaTitle = metatitle;
         bool result = dao.UpdateProduct(model);
         if (result)
         {
             return(RedirectToAction("Index", "Product"));
         }
         else
         {
             ModelState.AddModelError("UpdateProductError", "Cập nhật chưa thành công");
         }
     }
     else
     {
     }
     SetViewBag();
     return(View(model));
 }
 public ActionResult CreateProduct(Product model)
 {
     if (ModelState.IsValid)
     {
         var  dao   = new ProductDAO();
         bool exits = dao.ProductExist(model.Name);
         if (!exits)
         {
             //Lấy ra user đăng nhập để gán vào CreatedBY
             UserLogin userlogin = (UserLogin)Session["USER_SESSION"];
             model.CreatedBy = userlogin.UserName;
             string metatitle = CastString.Cast(model.Name);
             model.MetaTitle = metatitle;
             bool result = dao.CreateProduct(model);
             if (result)
             {
                 return(RedirectToAction("Index", "Product"));
             }
             else
             {
                 ModelState.AddModelError("CreateProductError", "Tạo mới không thành công");
             }
         }
         else
         {
             ModelState.AddModelError("CreateProductError", "Tên sản phẩm này đã có");
         }
     }
     SetViewBag();
     return(View(model));
 }
Exemple #3
0
 public ActionResult UpdateEvent(_event model)
 {
     if (ModelState.IsValid)
     {
         var dao = new EventsDAO();
         //Kiểm tra xem tên sự kiện này đã có chưa
         bool exist = dao.EventExistForUpdate(model.Name, Convert.ToInt32(model.ID));
         if (!exist)
         {
             UserLogin userlogin = (UserLogin)Session["USER_SESSION"];
             model.ModifiedBy = userlogin.UserName;
             string metatitle = CastString.Cast(model.Name);
             model.MetaTitle = metatitle;
             bool result = dao.UpdateEvent(model);
             if (result)
             {
                 SetAltert("Cập nhật sự kiện thành công", 0);
                 return(RedirectToAction("Index", "Events"));
             }
             else
             {
                 SetAltert("Chưa cập nhật sự kiện được", 2);
             }
         }
         else
         {
             SetAltert("Sự kiện này đã tồn tại", 2);
         }
     }
     else
     {
     }
     return(View(model));
 }
 public ActionResult CreateProductCategory(ProductCategory model)
 {
     if (ModelState.IsValid)
     {
         //Kiểm tra xem tên loại sản phẩm đã có chư
         var  dao    = new ProductCategoryDAO();
         bool exsits = dao.ProductCategoryExist(model.Name);
         if (!exsits)
         {
             UserLogin userlogin = (UserLogin)Session["USER_SESSION"];
             model.CreatedBy   = userlogin.UserName;
             model.CreatedDate = DateTime.Now;
             string metatitle = CastString.Cast(model.Name);
             model.MetaTitle = metatitle;
             bool result = dao.CreateProductCategory(model);
             if (result)
             {
                 return(RedirectToAction("Index", "ProductCategory"));
             }
             else
             {
                 ModelState.AddModelError("CreateProdCategoryError", "Tạo mới không thành công");
             }
         }
         else
         {
             //trường hợp tên đã có
             ModelState.AddModelError("CreateProdCategoryError", "Tên loại sản phẩm này đã có");
         }
     }
     else
     {
     }
     return(View(model));
 }
Exemple #5
0
        //public JsonResult saveImages(long id, string images)
        //{
        //    //tên biến phải trùng với tên data truyền qua từ Ajax

        //    JavaScriptSerializer serializer = new JavaScriptSerializer();
        //    var listImages = serializer.Deserialize<List<string>>(images);
        //    XElement xElement = new XElement("Images");
        //    foreach (var item in listImages)
        //    {
        //        xElement.Add(new XElement("image", item));
        //    }
        //    try
        //    {
        //        var dao = new GalleryDAO();
        //        dao.updateImage(id, xElement.ToString());
        //        return Json(new
        //        {
        //            status = true
        //        });
        //    }
        //    catch (Exception ex)
        //    {
        //        return Json(new
        //        {
        //            status = false
        //        });
        //    }

        //}



        //Xóa Album không gian quán
        public ActionResult DeleteGallery(long id)
        {
            //Lấy ra 1 dòng Gallery theo ID truyền vào
            var          dao          = new GalleryDAO();
            ImageGallery imageGallery = dao.imageGalleryDetail(id);
            string       imagePath    = Request.MapPath(imageGallery.ImagePath);

            if (System.IO.File.Exists(imagePath))
            {
                //Xóa luôn hình đại diện của Album trên server
                System.IO.File.Delete(imagePath);
            }
            //lấy ra tên album để làm folder và remove khoảng trắng
            var folder = CastString.Cast(imageGallery.Name.ToString());

            //tìm folder theo đường dẫn
            string path   = "/Data/Galleries/" + folder;
            bool   exists = System.IO.Directory.Exists(Server.MapPath(path));

            if (exists)
            {
                //Xóa Folder chứa hình chi của album
                DirectoryInfo dir = new DirectoryInfo(Server.MapPath(path));
                dir.GetFiles("*", SearchOption.AllDirectories).ToList().ForEach(file => file.Delete());
                Directory.Delete(Server.MapPath(path));
            }

            //Xóa Album trong Database
            dao.DeleteGallery(id);
            return(RedirectToAction("Index"));
        }
Exemple #6
0
 public ActionResult CreateEvent(_event model)
 {
     if (ModelState.IsValid)
     {
         var  dao   = new EventsDAO();
         bool exits = dao.EventExist(model.Name);
         if (!exits)
         {
             //Lấy ra user đăng nhập để gán vào CreatedBY
             UserLogin userlogin = (UserLogin)Session["USER_SESSION"];
             model.CreatedBy = userlogin.UserName;
             string metatitle = CastString.Cast(model.Name);
             model.MetaTitle = metatitle;
             bool result = dao.CreateEvent(model);
             if (result)
             {
                 SetAltert("Tạo sự kiện thành công", 0);
                 return(RedirectToAction("Index", "Events"));
             }
             else
             {
                 SetAltert("Chưa tạo được sự kiện", 2);
             }
         }
         else
         {
             SetAltert("Sự kiện này đã có", 2);
         }
     }
     return(View(model));
 }
Exemple #7
0
        public ActionResult UpdateBookCategory(BookCategory model)
        {
            if (ModelState.IsValid)
            {
                var dao = new BookCategoryDAO();
                //Kiểm tra xem tên loại sách này đã có chưa
                var exist = dao.BookCategoryExistForUpdate(model.Name, model.ID);
                if (!exist)
                {
                    UserLogin userlogin = (UserLogin)Session["USER_SESSION"];
                    model.ModifiedBy = userlogin.UserName;
                    string metatitle = CastString.Cast(model.Name);
                    model.MetaTitle = metatitle;
                    bool result = dao.UpdateBookCategory(model);
                    if (result)
                    {
                        SetAltert("Update loại sách thành công", 0);
                        return(RedirectToAction("Index", "BookCategory"));
                    }
                    else
                    {
                        SetAltert("Chưa cập nhật được", 2);
                    }
                }
                else
                {
                    SetAltert("Tên loại sách này đã có", 2);
                }
            }
            else
            {
            }

            return(View(model));
        }
        public ActionResult CreatePublisher(Publisher entity)
        {
            var dao = new  PublisherDAO();

            if (ModelState.IsValid)
            {
                //Kiểm tra xem tên NXB dự định tạo đã có chưa
                if (dao.ExistPublisherForCreate(entity.Name) == false)
                {
                    string metatitle = CastString.Cast(entity.Name);
                    entity.MetaTitle   = metatitle;
                    entity.CreatedDate = DateTime.Now;
                    bool result = dao.CreatePublisher(entity);
                    if (result)
                    {
                        SetAltert("Tạo mới nhà xuất bản thành công", 0);
                        return(RedirectToAction("Index", "Publisher"));
                    }
                    else
                    {
                        SetAltert("Chưa tạo được nhà xuất bản, vui lòng thử lại", 1);
                    }
                }
                else
                {
                    SetAltert("Nhà xuất bản này đã có trong hệ thống", 2);
                }
            }
            return(View(entity));
        }
Exemple #9
0
 public ActionResult UpdateAbout(About model)
 {
     if (ModelState.IsValid)
     {
         var       dao       = new AboutDAO();
         UserLogin userlogin = (UserLogin)Session["USER_SESSION"];
         model.ModifiedBy = userlogin.UserName;
         //Kiểm tra xem tên sách này đã có chưa
         bool exist = dao.AboutExistForUpdate(model.Name, model.ID);
         if (!exist)
         {
             string metatitle = CastString.Cast(model.Name);
             model.MetaTitle = metatitle;
             bool result = dao.UpdateAbout(model);
             if (result)
             {
                 SetAltert("Cập nhật thành công", 0);
                 return(RedirectToAction("Index", "ABout"));
             }
             else
             {
                 SetAltert("Cập nhật không thành công", 2);
             }
         }
         else
         {
             SetAltert("Bài giới thiệu này đã có", 2);
         }
     }
     else
     {
     }
     return(View(model));
 }
        public ActionResult UpdateCategory(Category model)
        {
            var dao = new CategoryDAO();

            if (ModelState.IsValid)
            {
                UserLogin modifiedby = (UserLogin)Session["USER_SESSION"];
                model.ModifiedBy = modifiedby.UserName;
                string metatitle = CastString.Cast(model.Name);
                model.MetaTitle = metatitle;
                bool result = dao.UpdateCategory(model);
                if (result)
                {
                    return(RedirectToAction("Index", "Category"));
                }
                else
                {
                    ModelState.AddModelError("UpdateCategoryError", "Chưa cập nhật được ");
                }
            }
            else
            {
                ModelState.AddModelError("UpdateCategoryError", "Thông tin không hợp lệ");
            }
            return(View(model));
        }
Exemple #11
0
 public ActionResult CreateAbout(About model)
 {
     if (ModelState.IsValid)
     {
         var dao = new AboutDAO();
         //Lấy ra user đăng nhập để gán vào CreatedBY
         UserLogin userlogin = (UserLogin)Session["USER_SESSION"];
         model.CreatedBy = userlogin.UserName;
         bool exits = dao.AboutExistForCreate(model.Name);
         if (!exits)
         {
             string metatitle = CastString.Cast(model.Name);
             model.MetaTitle   = metatitle;
             model.CreatedDate = DateTime.Now;
             bool result = dao.CreateABout(model);
             if (result)
             {
                 SetAltert("Tạo mới bài giới thiệu thành công", 0);
                 return(RedirectToAction("Index", "About"));
             }
             else
             {
                 SetAltert("Tạo mới không thành công", 2);
             }
         }
         else
         {
             SetAltert("Bài giới thiệu này đã có", 2);
         }
     }
     return(View(model));
 }
Exemple #12
0
        public ActionResult UpdateAuthor(Author entity)
        {
            var dao = new AuthorDAO();

            if (ModelState.IsValid)
            {
                //Kiểm tra xem tên tác giả để cập nhật đã có trong hệ thống chưa?
                bool exist = dao.ExistAuthorForUpdate(entity.Name, entity.ID);
                if (!exist)
                {
                    string metatitle = CastString.Cast(entity.Name);
                    entity.MetaTitle = metatitle;
                    bool result = dao.UpdateAuthor(entity);
                    if (result)
                    {
                        SetAltert("Cập nhật thông tin tác giả thành công", 0);
                        return(RedirectToAction("Index", "Author"));
                    }
                    else
                    {
                        SetAltert("Chưa cập nhật được, vui lòng thử lại", 2);
                    }
                }
                else
                {
                    SetAltert("Tác giả này đã có trong hệ thống, vui lòng chọn tác giả khác", 2);
                }
            }
            return(View(entity));
        }
        public ActionResult UpdateProductCategory(ProductCategory model)
        {
            if (ModelState.IsValid)
            {
                var       dao       = new ProductCategoryDAO();
                UserLogin userlogin = (UserLogin)Session["USER_SESSION"];
                model.ModifiedBy = userlogin.UserName;
                string metatitle = CastString.Cast(model.Name);
                model.MetaTitle = metatitle;
                bool result = dao.UpdateProductCategory(model);
                if (result)
                {
                    return(RedirectToAction("Index", "ProductCategory"));
                }
                else
                {
                    ModelState.AddModelError("UpdateProdCategoryError", "Chưa cập nhật được");
                }
            }
            else
            {
            }

            return(View(model));
        }
Exemple #14
0
        public ActionResult CreateAuthor(Author entity)
        {
            var dao = new AuthorDAO();

            if (ModelState.IsValid)
            {
                //Kiểm tra xem tên Author dự định tạo đã có chưa
                if (dao.ExistAuthorForCreate(entity.Name) == false)
                {
                    string metatitle = CastString.Cast(entity.Name);
                    entity.MetaTitle   = metatitle;
                    entity.CreatedDate = DateTime.Now;
                    bool result = dao.CreateAuthor(entity);
                    if (result)
                    {
                        SetAltert("Tạo mới tác giả thành công", 0);
                        return(RedirectToAction("Index", "Author"));
                    }
                    else
                    {
                        SetAltert("Chưa tạo được tác giả, vui lòng thử lại", 1);
                    }
                }
                else
                {
                    SetAltert("Tác giả này đã có trong hệ thống", 2);
                }
            }
            return(View(entity));
        }
Exemple #15
0
 public ActionResult Create(LawCorner model)
 {
     if (ModelState.IsValid)
     {
         var dao = new LawCornerDAO();
         //Lấy ra user đăng nhập để gán vào CreatedBY
         UserLogin userlogin = (UserLogin)Session["USER_SESSION"];
         model.CreatedBy = userlogin.UserName;
         bool exits = dao.LawCornerExist(model.Name);
         if (!exits)
         {
             string metatitle = CastString.Cast(model.Name);
             model.MetaTitle   = metatitle;
             model.CreatedDate = DateTime.Now;
             bool result = dao.CreateLawCorner(model);
             if (result)
             {
                 SetAltert("Tạo tin  thành công", 0);
                 return(RedirectToAction("Index", "LawCorner"));
             }
             else
             {
                 SetAltert("Tạo mới không thành công", 2);
             }
         }
         else
         {
             SetAltert("Tiêu đề này đã có", 2);
         }
     }
     return(View(model));
 }
Exemple #16
0
        public ActionResult UpdateContent(Content model)
        {
            if (ModelState.IsValid)
            {
                var dao = new ContentDAO();
                if (model.TopHot == true)
                {
                    bool TopHotExist = dao.TopHotForUpdate(model.ID);
                    if (!TopHotExist)
                    {
                        UserLogin userlogin = (UserLogin)Session["USER_SESSION"];
                        model.ModifiedBy   = userlogin.UserName;
                        model.ModifiedDate = DateTime.Now;
                        string metatitle = CastString.Cast(model.Name);
                        model.MetaTitle = metatitle;
                        bool result = dao.UpdateContent(model);
                        if (result)
                        {
                            SetAltert("Cập nhật thành công", 0);
                            return(RedirectToAction("Index", "Content"));
                        }
                        else
                        {
                            //Trường hợp cập nhật không thành công
                            SetAltert("Cập nhật không thành công, vui lòng thử lại", 2);
                        }
                    }
                    else
                    {
                        SetAltert("Tạm thời không thể thiết lập tin này là TopHot, vì đang có tin TopHop", 2);
                    }
                }
                else
                {
                    UserLogin userlogin = (UserLogin)Session["USER_SESSION"];
                    model.ModifiedBy   = userlogin.UserName;
                    model.ModifiedDate = DateTime.Now;
                    string metatitle = CastString.Cast(model.Name);
                    model.MetaTitle = metatitle;
                    bool result = dao.UpdateContent(model);
                    if (result)
                    {
                        SetAltert("Cập nhật thành công", 0);
                        return(RedirectToAction("Index", "Content"));
                    }
                    else
                    {
                        //Trường hợp cập nhật không thành công
                        SetAltert("Cập nhật không thành công, vui lòng thử lại", 2);
                    }
                }
            }
            else
            {
            }

            SetViewBag();
            return(View());
        }
Exemple #17
0
        /// <summary>
        ///  根据欧拉角设置一个物体的旋转;
        /// </summary>
        /// <param name="gameObjectName"></param>
        /// <param name="rotStr"></param>
        /// <returns></returns>
        public static bool SetRotation(string gameObjectName, string rotStr)
        {
            float[] rotation = CastString.CastToNumbers <float>(rotStr);

            GetGameObject(gameObjectName).transform.position = new Vector3(rotation[0], rotation[1], rotation[2]);

            return(true);
        }
Exemple #18
0
        public static bool Color(string gameObjectName, string color)
        {
            float[] colors = CastString.CastToNumbers <float>(color);

            GetGameObject(gameObjectName).GetComponent <MeshRenderer>().material.color = new Color(colors[0], colors[1], colors[2]);

            return(true);
        }
Exemple #19
0
        public ActionResult CreateContent(Content model)
        {
            var dao = new ContentDAO();

            if (ModelState.IsValid)
            {
                //Trường hợp chọn tin là TopHot
                if (model.TopHot == true)
                {
                    //Kiểm tra xem hiện tại đang có tin nào thuộc TopHot không
                    bool TopHotExist = dao.TopHotForCreate();
                    if (!TopHotExist)
                    {
                        //Lấy ra username đang sử dụng
                        UserLogin userlogin = (UserLogin)Session["USER_SESSION"];
                        model.CreatedBy = userlogin.UserName;
                        string metatitle = CastString.Cast(model.Name);
                        model.MetaTitle = metatitle;
                        long id = dao.CreateContent(model);
                        if (id > 0)
                        {
                            SetAltert("Tạo mới tin tức thành công", 0);
                            return(RedirectToAction("Index", "Content"));
                        }
                        else
                        {
                            SetAltert("Chưa tạo mới được tin tức, vui lòng thử lại", 2);
                        }
                    }
                    else
                    {
                        SetAltert("Tạm thời không thể thiết lập tin này là TopHot, vì đang có tin TopHop", 2);
                    }
                }
                else
                {
                    //Lấy ra username đang sử dụng
                    UserLogin userlogin = (UserLogin)Session["USER_SESSION"];
                    model.CreatedBy = userlogin.UserName;
                    long id = dao.CreateContent(model);
                    if (id > 0)
                    {
                        SetAltert("Tạo mới tin tức thành công", 0);
                        return(RedirectToAction("Index", "Content"));
                    }
                    else
                    {
                        SetAltert("Chưa tạo mới được tin tức, vui lòng thử lại", 2);
                    }
                }
            }

            SetViewBag();
            return(View());
        }
        /// <summary>
        ///  循环执行指定的范围;
        ///
        ///  格式为 loop:[step|position],count=(int)数值 ,number=数值;
        ///
        ///  注意: 正直是向前定位,从指定为位置执行到当前位置; 负值是向后定位,从当前位置执行到指定位置;
        /// </summary>
        /// <param name="josnData"></param>
        /// <returns></returns>
        private bool Loop(JsonData jsonData)
        {
            int[] parameters = CastString.CastToNumbers <int>(jsonData[1].ToString());

            if (jsonData[0].ToString().ToLower() == "step")
            {
                LitJsonParsing.Instance.ExecuteLoopStep(parameters[0], parameters[1]);
            }
            else
            {
                // TODO
            }

            return(true);
        }
Exemple #21
0
        /// <summary>
        ///  Unity的等待事件,单位秒;
        /// </summary>
        /// <param name="waitTime"></param>
        /// <param name="actionName"></param>
        /// <returns></returns>
        public static bool OnWaitSecond(string waitTime, string actionName = null, string parameters = null)
        {
            float time = CastString.CastToNumbers <float>(waitTime)[0];

            if (string.IsNullOrEmpty(parameters))
            {
                UnityEventService.OnWaitSecond(time, EventFunctionLibrary.GetAction(actionName));
            }

            else
            {
                UnityEventService.OnWaitSecond(time, EventFunctionLibrary.GetActionT(actionName), parameters);
            }

            return(true);
        }
Exemple #22
0
        /// <summary>
        /// 设置一个物体的位置;注意,如果该物体有父物体,则默认设置的是相对位置;
        /// </summary>
        /// <param name="gameObjectName"></param>
        /// <param name="posStr"></param>
        /// <returns></returns>
        public static bool SetPosition(string gameObjectName, string posStr)
        {
            float[] position = CastString.CastToNumbers <float>(posStr);

            GameObject go = GetGameObject(gameObjectName);

            if (go.transform.parent)
            {
                go.transform.localPosition = new Vector3(position[0], position[1], position[2]);
            }

            else
            {
                go.transform.position = new Vector3(position[0], position[1], position[2]);
            }

            return(true);
        }
        public ActionResult CreateCategory(Category model)
        {
            var dao = new CategoryDAO();

            if (ModelState.IsValid)
            {
                //kiểm tra xem tên loại tin này đã được tao chưa
                if (!dao.CategoryExits(model.Name))
                {
                    string metatitle = CastString.Cast(model.Name);
                    model.MetaTitle = metatitle;
                    var       createby  = Session["USER_SESSION"];
                    UserLogin userlogin = (UserLogin)Session["USER_SESSION"];
                    model.CreatedBy = userlogin.UserName;
                    long result = dao.CreateCategory(model);
                    if (result > 0)
                    {
                        return(RedirectToAction("Index", "Category"));
                    }
                    else
                    {
                        ModelState.AddModelError("CreateCategoryError", "Chưa tạo được loại tin");
                    }
                }
                else
                {
                    //Trường hợp đã tồn tại
                    ModelState.AddModelError("CreateCategoryError", "Tên loại tin này đã có");
                }
            }
            else
            {
                // ModelState.AddModelError("CreateCategoryError", "Thông tin không hợp lệ");
            }

            return(View(model));
        }
Exemple #24
0
 public ActionResult CreateBookCategory(BookCategory model)
 {
     if (ModelState.IsValid)
     {
         //Kiểm tra xem tên loại sản phẩm đã có chư
         var  dao    = new BookCategoryDAO();
         bool exsits = dao.BookCategoryExist(model.Name);
         if (!exsits)
         {
             UserLogin userlogin = (UserLogin)Session["USER_SESSION"];
             model.CreatedBy   = userlogin.UserName;
             model.CreatedDate = DateTime.Now;
             string metatitle = CastString.Cast(model.Name);
             model.MetaTitle = metatitle;
             bool result = dao.CreateBookCategory(model);
             if (result)
             {
                 SetAltert("Tạo mới loại sách thành công", 0);
                 return(RedirectToAction("Index", "BookCategory"));
             }
             else
             {
                 SetAltert("Chưa tạo loại sách được", 2);
             }
         }
         else
         {
             //trường hợp tên đã có
             SetAltert("Tên loại sách này đã có", 2);
         }
     }
     else
     {
     }
     return(View(model));
 }
Exemple #25
0
        public ActionResult UploadImageMethod()
        {
            if (Request.Files.Count != 0)
            {
                long id = Convert.ToInt64(Request["id"]);
                //lấy ra gallery cần upload hình
                var gallery = new GalleryDAO().imageGalleryDetail(id);
                //lấy ra tên album để làm folder và remove khoảng trắng
                var folder = CastString.Cast(gallery.Name.ToString());

                //Path lưu hình
                string path = "/Data/Galleries/" + folder + "/";

                List <string> listimage = new List <string>();
                for (int i = 0; i < Request.Files.Count; i++)
                {
                    HttpPostedFileBase file   = Request.Files[i];
                    int    fileSize           = file.ContentLength;
                    string fileName           = file.FileName;
                    string extension          = System.IO.Path.GetExtension(fileName);
                    string fileNameWithoutExt = fileName.Substring(0, fileName.Length - extension.Length);
                    fileNameWithoutExt = CastString.Cast(fileNameWithoutExt);
                    listimage.Add(path + fileNameWithoutExt + extension);
                }

                XElement xElement;
                //Kiểm tra xem hiện tại đang có hình chưa
                if (gallery.ImageDetail != null)
                {
                    //Nếu hiện tai đang có hình thìử dụng Root hiện tai
                    xElement = XElement.Parse(gallery.ImageDetail);
                }
                else
                {
                    //Nếu chưa có hình nào thì tạo Root là Images
                    xElement = new XElement("Images");
                }

                foreach (var item in listimage)
                {
                    xElement.Add(new XElement("image", item));
                }
                try
                {
                    var  dao    = new GalleryDAO();
                    bool result = dao.updateImage(id, xElement.ToString());
                    //Kiểm tra nếu như Add vào database thành công thì mới lưu hình lên server
                    if (result)
                    {
                        //kiểm tra xem hiện có folder nào chưa
                        bool exists = System.IO.Directory.Exists(Server.MapPath(path));
                        //Nếu đã có thì upload hình lên foler server
                        if (exists)
                        {
                            for (int i = 0; i < Request.Files.Count; i++)
                            {
                                HttpPostedFileBase file   = Request.Files[i];
                                int    fileSize           = file.ContentLength;
                                string fileName           = file.FileName;
                                string extension          = System.IO.Path.GetExtension(fileName);
                                string fileNameWithoutExt = fileName.Substring(0, fileName.Length - extension.Length);
                                fileNameWithoutExt = CastString.Cast(fileNameWithoutExt);
                                file.SaveAs(Server.MapPath(path + fileNameWithoutExt + extension));
                            }
                        }
                        else
                        {
                            //Nếu chưa có thì tạo folder với tên folder là tên Album
                            System.IO.Directory.CreateDirectory(Server.MapPath(path));
                            //Sau khi tạo folder xong, upload hình vào
                            for (int i = 0; i < Request.Files.Count; i++)
                            {
                                HttpPostedFileBase file   = Request.Files[i];
                                int    fileSize           = file.ContentLength;
                                string fileName           = file.FileName;
                                string extension          = System.IO.Path.GetExtension(fileName);
                                string fileNameWithoutExt = fileName.Substring(0, fileName.Length - extension.Length);
                                fileNameWithoutExt = CastString.Cast(fileNameWithoutExt);
                                file.SaveAs(Server.MapPath(path + fileNameWithoutExt + extension));
                            }
                        }
                    }
                    return(Content("ok"));
                }
                catch (Exception ex)
                {
                    return(Content("failed"));
                }
            }
            return(Content("failed"));
        }
Exemple #26
0
 public ActionResult CreateBook(Book model)
 {
     if (ModelState.IsValid)
     {
         var dao = new BooksDAO();
         //Lấy ra user đăng nhập để gán vào CreatedBY
         UserLogin userlogin = (UserLogin)Session["USER_SESSION"];
         model.CreatedBy = userlogin.UserName;
         bool exits = dao.bookExist(model.Name);
         if (!exits)
         {
             //Nếu chọn sách này là TopHot
             if (model.TopHot == true)
             {
                 bool TopHot = dao.TopHotForCreate();
                 if (!TopHot)
                 {
                     string metatitle = CastString.Cast(model.Name);
                     model.MetaTitle   = metatitle;
                     model.CreatedDate = DateTime.Now;
                     bool result = dao.CreateBook(model);
                     if (result)
                     {
                         SetAltert("Tạo mới sách thành công", 0);
                         return(RedirectToAction("Index", "Books"));
                     }
                     else
                     {
                         SetAltert("Tạo mới không thành công", 2);
                     }
                 }
                 else
                 {
                     SetAltert("Tạm thời không thể thiết lập TopHot cho sách này, vì hiện đang có 1 sách thuộc TopHot", 2);
                 }
             }
             else
             {
                 string metatitle = CastString.Cast(model.Name);
                 model.MetaTitle   = metatitle;
                 model.CreatedDate = DateTime.Now;
                 bool result = dao.CreateBook(model);
                 if (result)
                 {
                     SetAltert("Tạo mới sách thành công", 0);
                     return(RedirectToAction("Index", "Books"));
                 }
                 else
                 {
                     SetAltert("Tạo mới không thành công", 2);
                 }
             }
         }
         else
         {
             SetAltert("Tên sách này đã có", 2);
         }
     }
     SetViewBag();
     return(View(model));
 }
Exemple #27
0
 public ActionResult UpdateBook(Book model)
 {
     if (ModelState.IsValid)
     {
         var       dao       = new BooksDAO();
         UserLogin userlogin = (UserLogin)Session["USER_SESSION"];
         model.ModifiedBy = userlogin.UserName;
         //Kiểm tra xem tên sách này đã có chưa
         bool exist = dao.bookExistForUpdate(model.Name, model.ID);
         if (!exist)
         {
             //Trường hợp chọn sách là Tophot
             if (model.TopHot == true)
             {
                 bool tophot = dao.TopHotForUpdate(model.ID);
                 //Kiểm tra xem hiện tại đang có sách nào thuộc TopHot chưa
                 if (!tophot)
                 {
                     string metatitle = CastString.Cast(model.Name);
                     model.MetaTitle = metatitle;
                     bool result = dao.UpdateBook(model);
                     if (result)
                     {
                         SetAltert("Cập nhật thành công", 0);
                         return(RedirectToAction("Index", "Books"));
                     }
                     else
                     {
                         SetAltert("Cập nhật không thành công", 2);
                     }
                 }
                 else
                 {
                     SetAltert("Tạm thời không thể thiết lập TopHot cho sách này, vì hiện đang có 1 sách thuộc TopHot", 2);
                 }
             }
             else
             {
                 string metatitle = CastString.Cast(model.Name);
                 model.MetaTitle = metatitle;
                 bool result = dao.UpdateBook(model);
                 if (result)
                 {
                     SetAltert("Cập nhật thành công", 0);
                     return(RedirectToAction("Index", "Books"));
                 }
                 else
                 {
                     SetAltert("Cập nhật không thành công", 2);
                 }
             }
         }
         else
         {
             SetAltert("Tên sách này đã có", 2);
         }
     }
     else
     {
     }
     SetViewBag();
     return(View(model));
 }
Exemple #28
0
        /// <summary>
        ///  设置物体的缩放;
        /// </summary>
        /// <param name="gameObject"></param>
        /// <param name="scaleStr"></param>
        public static void SetScale(this GameObject gameObject, string scaleStr)
        {
            float[] scales = CastString.CastToNumbers <float>(scaleStr);

            gameObject.transform.localScale = new Vector3(scales[0], scales[1], scales[2]);
        }
Exemple #29
0
        /// <summary>
        ///  设置物体的旋转;
        /// </summary>
        /// <param name="gameObject"></param>
        /// <param name="rotStr"></param>
        public static void SetRotation(this GameObject gameObject, string rotStr)
        {
            float[] rotations = CastString.CastToNumbers <float>(rotStr);

            gameObject.transform.eulerAngles = new Vector3(rotations[0], rotations[1], rotations[2]);
        }
Exemple #30
0
        /// <summary>
        ///  设置物体的位置;
        /// </summary>
        /// <param name="gameObject"></param>
        /// <param name="posStr"></param>
        public static void SetPosition(this GameObject gameObject, string posStr)
        {
            float[] positions = CastString.CastToNumbers <float>(posStr);

            gameObject.transform.position = new Vector3(positions[0], positions[1], positions[2]);
        }