예제 #1
0
        public ActionResult AdvertiseEdit(FormCollection collection, onsoft.Models.Advertise advertise)
        {
            if (Request.Cookies["Username"] != null)
            {
                advertise.Name        = collection["Name"];
                advertise.Image       = collection["Image"];
                advertise.Height      = Convert.ToInt32(collection["Height"]);
                advertise.Width       = Convert.ToInt32(collection["Width"]);
                advertise.Position    = Convert.ToInt32(collection["sllPossition"]);
                advertise.Link        = collection["Link"];
                advertise.Target      = collection["sllTarget"];
                advertise.Orders      = Convert.ToInt32(collection["Order"]);
                advertise.Active      = (collection["Active"] == "false") ? false : true;
                advertise.Description = collection["Description"];
                advertise.Lang        = Session["Lang"] != null ? Session["Lang"].ToString() : "vi";
                string groid = collection["Cat"];
                if (groid != null && groid != "")
                {
                    advertise.GrpID = int.Parse(groid);
                }
                else
                {
                    advertise.GrpID = 0;
                }
                db.Entry(advertise).State = EntityState.Modified;
                db.SaveChanges();

                return(RedirectToAction("AdvertiseIndex"));
            }
            else
            {
                return(Redirect("/Admins/admins"));
            }
        }
예제 #2
0
        public ActionResult AddMultilImage(IEnumerable <HttpPostedFileBase> fileImg, FormCollection aForm)
        {
            if (Request.Cookies["Username"] != null)
            {
                int ID;
                var tmp = db.Advertises.Select(a => (int?)a.Id).Max();
                //if (tmp == null)
                //    tmp = 1;
                foreach (var file in fileImg)
                {
                    if (tmp == null)
                    {
                        ID = 1; tmp = 1;
                    }
                    else
                    {
                        ID = db.Advertises.Select(a => a.Id).Max();
                    }

                    if (file.ContentLength > 0)
                    {
                        //var b = (from k in db.ProImages select k.Id).Max();
                        var    ab       = Request.Files["fileImg"];
                        String FileExtn = System.IO.Path.GetExtension(file.FileName).ToLower();
                        if (!(FileExtn == ".jpg" || FileExtn == ".png" || FileExtn == ".gif"))
                        {
                            ViewBag.error = "Only jpg, gif and png files are allowed!";
                        }
                        else
                        {
                            onsoft.Models.Advertise aImage = new onsoft.Models.Advertise();
                            var Filename = Path.GetFileName(file.FileName);
                            //List<string> sizeImg = new List<string>();
                            //sizeImg.Add("_huge");
                            //sizeImg.Add("_big");
                            //sizeImg.Add("_noz");
                            //sizeImg.Add("_small");
                            //string co = "";
                            //string kco = "";
                            //for (int i = 0; i < sizeImg.Count; i++)
                            //{
                            //    var a = Filename.LastIndexOf(sizeImg[i]);
                            //    if (a > 0)
                            //    {
                            //        co = Filename.Substring(0, a);
                            //        kco = sizeImg[i];
                            //        break;
                            //    }
                            //}
                            //var fileName = String.Format("{0}" + kco + ".jpg", Guid.NewGuid().ToString());
                            //String imgPath = String.Format("Uploads/{0}{1}", file.FileName, FileExtn);
                            //file.Save(String.Format("{0}{1}", Server.MapPath("~"), imgPath), Img.RawFormat);
                            var path = Path.Combine(Server.MapPath(Url.Content("/Uploads")), Filename);
                            file.SaveAs(path);

                            if (Convert.ToInt32(aForm["sllPossition"]) == 0)
                            {
                                aImage.Position = 0;
                            }
                            else if (Convert.ToInt32(aForm["sllPossition"]) == 1)
                            {
                                aImage.Position = 1;
                            }
                            else if (Convert.ToInt32(aForm["sllPossition"]) == 2)
                            {
                                aImage.Position = 2;
                            }
                            else if (Convert.ToInt32(aForm["sllPossition"]) == 3)
                            {
                                aImage.Position = 3;
                            }

                            aImage.Id     = ID + 1;
                            aImage.Name   = "QC thứ " + ID;
                            aImage.Orders = 0;
                            aImage.Click  = 0;
                            aImage.Target = "_top";
                            aImage.Width  = 0;
                            aImage.Height = 0;
                            //aImage.Position = 0;
                            aImage.Image = "/Uploads/" + Filename;
                            //img.Date = DateTime.Now;
                            db.Advertises.Add(aImage);
                            db.SaveChanges();
                        }
                    }
                    var fd = file;
                }
                return(RedirectToAction("AdvertiseIndex"));
            }
            else
            {
                return(Redirect("/admins/admins"));
            }
        }
예제 #3
0
        public ActionResult AdvertiseCreate(FormCollection collection, onsoft.Models.Advertise advertise)
        {
            if (Request.Cookies["Username"] != null)
            {
                advertise.Name   = collection["Name"];;
                advertise.Image  = collection["Picture"];
                advertise.Width  = Convert.ToInt32(collection["Width"]);
                advertise.Height = Convert.ToInt32(collection["Height"]);
                advertise.Orders = Convert.ToInt32(collection["Order"]);
                advertise.Link   = collection["Link"];
                advertise.Click  = Convert.ToInt32(collection["Click"]);

                advertise.Active      = (collection["Active"] == "false") ? false : true;
                advertise.Lang        = Session["Lang"] != null ?  Session["Lang"].ToString() : "vi";
                advertise.Position    = Convert.ToInt32(collection["sllPossition"]);
                advertise.Description = collection["Description"];
                if (collection["FromDate"] != null)
                {
                    advertise.FromDate = Convert.ToDateTime(collection["FromDate"]);
                }
                if (collection["ToDate"] != null)
                {
                    advertise.ToDate = Convert.ToDateTime(collection["ToDate"]);
                }

                string groid = collection["Cat"];
                if (groid != null && groid != "")
                {
                    advertise.GrpID = int.Parse(groid);
                }
                else
                {
                    advertise.GrpID = 0;
                }
                if (Convert.ToInt32(collection["sllTarget"]) == 0)
                {
                    advertise.Target = "_blank";
                }
                else if (Convert.ToInt32(collection["sllTarget"]) == 1)
                {
                    advertise.Target = "_self";
                }
                else if (Convert.ToInt32(collection["sllTarget"]) == 2)
                {
                    advertise.Target = "_Parient";
                }
                else if (Convert.ToInt32(collection["sllTarget"]) == 3)
                {
                    advertise.Target = "_top";
                }

                advertise.Click = 0;

                db.Advertises.Add(advertise);
                db.SaveChanges();
                return(RedirectToAction("AdvertiseIndex"));
            }
            else
            {
                return(Redirect("/Admins/admins"));
            }
        }