コード例 #1
0
        //
        // GET: /Administrator/Designs/

        public ActionResult Index(string id)
        {
            int admin = base.Authentication();
            if (admin == 0)
            {
                return Redirect("~/member/logout");
            }
            else if (admin == 1)
            {
                base.LoadMenu();
                int currentPage = Paging.GetPage(id);
                decimal totalRecord = GlobalInfo.NumberRecordInPage;
                Designs exhibitionsModels = new Designs();
                decimal totalDesign = exhibitionsModels.TotalDesign();
                int totalPage = (int)Math.Ceiling(Convert.ToDecimal(totalDesign / totalRecord));
                Paging.numPage = totalPage;
                Paging.numLinkDisplay = GlobalInfo.NumLinkPagingDisplay;
                Paging.currentPage = currentPage;
                string url = "administrator/designs/index";
                ViewBag.pagingString = Paging.GenerateLinkPaging(url);
                ViewBag.Title += " Designs";
                Session["back-url"] = "~/administrator/designs/";
                return View(exhibitionsModels.ListDesign((int)((currentPage - 1) * totalRecord), (int)totalRecord));
            }
            else
            {
                Session["errorContorllerAction"] = true;
                return Redirect("~/administrator");
            }
        }
コード例 #2
0
 public ActionResult ExhibitionDesign(string id)
 {
     int admin = base.Authentication();
     if (admin == 0)
     {
         return Redirect("~/member/logout");
     }
     else if (admin == 1)
     {
         base.LoadMenu();
         try
         {
             int idd = Convert.ToInt16(id);
             Designs designsModels = new Designs();
             designsModels.ID = idd;
             designsModels = designsModels.GetNavigationWithID("Exhibitions");
             ViewBag.Title += " Exhinitions of " + designsModels.Name + " Designs";
             ViewBag.designID = idd;
             Session["back-url"] = "~/administrator/exhibitions/exhibitiondesign/" + idd;
             return View(designsModels.Exhibitions.ToList());
         }
         catch
         {
             Session["admin"] = null;
             return Redirect("~/");
         }
     }
     else
     {
         Session["errorContorllerAction"] = true;
         return Redirect("~/administrator");
     }
 }
コード例 #3
0
        public ActionResult Submit(string id, FormCollection form, HttpPostedFileBase Images)
        {
            base.Authentication();
            if (id != null)
            {
                if (Validator.ISAlias(id))
                {
                    try
                    {
                        var db = new FineArtContext();
                        bool IsSold = false;
                        decimal PriceSold = 0;
                        bool IsPaidStudent = false;
                        Competitions competition = db.Competitions
                            .Include("Award")
                            .Include("Condition")
                            .Include("Kind")
                            .Where(c => c.Alias == id && c.DeadlineDate > DateTime.Now).First();
                        if (form["submit_design"] == null)
                        {

                        }
                        else
                        {
                            StringBuilder stringBuilder = new StringBuilder();
                            stringBuilder.Append("<ul>");
                            if (form["Name"].Trim() == "")
                            {
                                stringBuilder.Append("<li>Design name not blank.</li>");
                            }

                            if (form["Alias"].Trim() == "" || !Validator.ISAlias(form["Alias"]))
                            {
                                stringBuilder.Append("<li>Design alias not blank. Only contain a-z and \"-\"</li>");
                            }
                            else
                            {
                                string alias = form["Alias"].Trim();
                                var designExists = db.Designs.Where(d => d.Alias == alias).FirstOrDefault();
                                if (designExists != null)
                                {
                                    stringBuilder.Append("<li>This alias has been exists in database, try other</li>");
                                }
                            }

                            if (Images == null)
                            {
                                stringBuilder.Append("<li>Please choose your design image</li>");
                            }
                            if (form["Kind"] == "-1")
                            {
                                stringBuilder.Append("<li>Please choose kind for your design</li>");
                            }

                            if (form["IsSold"] == "on")
                            {
                                IsSold = true;
                                if (!Validator.ISPrice(form["PriceSold"]))
                                {
                                    stringBuilder.Append("<li>Please type price for your design</li>");
                                }
                            }
                            else if (form["PriceSold"] != "")
                            {
                                stringBuilder.Append("<li>You have not chosen to sell this design</li>");
                            }
                            if (form["IsPaidStudent"] == "on")
                            {
                                IsPaidStudent = true;
                                if (form["IsSold"] == null)
                                {
                                    stringBuilder.Append("<li>You have not chosen to sell this design</li>");
                                }
                            }

                            if (stringBuilder.ToString() != "<ul>")
                            {
                                ViewBag.dataForm = form;
                                stringBuilder.Append("</ul>");
                                ViewBag.error = stringBuilder.ToString();
                            }
                            else
                            {
                                ImagesClass imageLibs = new ImagesClass(Images);
                                string fileNameThumb = Server.MapPath("~/Content/Images/designs/thumbnails/" + form["Alias"] + ".jpg");
                                string fileNameBig = Server.MapPath("~/Content/Images/designs/bigimages/" + form["Alias"] + ".jpg");
                                imageLibs.ResizeAndCreateImage(fileNameThumb, 190);
                                imageLibs.ResizeAndCreateImage(fileNameBig, 700);
                                string username = Session["user-loged"].ToString();
                                Members member = db.Members.Where(m => m.Username == username).First();
                                int kindID = Convert.ToInt16(form["Kind"]);

                                Kinds kind = competition.Kind.Where(k => k.ID == kindID).First();
                                if (IsSold)
                                {
                                    PriceSold = Convert.ToDecimal(form["PriceSold"]);
                                }
                                else
                                {
                                    PriceSold = 0;
                                }
                                Designs design = new Designs
                                {
                                    Name = form["Name"].Trim(),
                                    Alias = form["Alias"].Trim(),
                                    Images = form["Alias"].Trim() + ".jpg",
                                    Competition = competition,
                                    DatePost = DateTime.Now,
                                    Description = form["Description"].Trim(),
                                    IsSold = IsSold,
                                    IsPaidStudent = IsPaidStudent,
                                    PriceSold = PriceSold,
                                    Member = member,
                                    Kind = kind
                                };
                                db.Designs.Add(design);
                                db.SaveChanges();
                                Session["success"] = form["Alias"];
                                return Redirect("~/design/submit/" + competition.Alias + "#submition");
                            }
                        }

                        return View(competition);
                    }
                    catch
                    {
                        return Redirect("~/");
                    }
                }
                else
                {
                    return Redirect("~/");
                }
            }
            else
            {
                return Redirect("~/");
            }
        }