public ActionResult ConditionCompetition(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);
             ViewBag.competitionID = idd;
             Competitions competitionsModels = new Competitions();
             competitionsModels.ID = idd;
             competitionsModels = competitionsModels.ListNavigation("Condition");
             ViewBag.Title += " Conditions of " + competitionsModels.Name + " Competition";
             return View(competitionsModels.Condition.ToList());
         }
         catch
         {
             Session["admin"] = null;
             return Redirect("~/");
         }
     }
     else
     {
         Session["errorContorllerAction"] = true;
         return Redirect("~/administrator");
     }
 }
 /**
  * Controller: Competition
  * Action: Index
  * List all competitions
  * Author: Le Dang Son
  * Date: 08/08/2012
  */
 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;
         Competitions competitionsModels = new Competitions();
         decimal totalCompetition = competitionsModels.TotalCompetition();
         int totalPage = (int)Math.Ceiling(Convert.ToDecimal(totalCompetition / totalRecord));
         Paging.numPage = totalPage;
         Paging.numLinkDisplay = GlobalInfo.NumLinkPagingDisplay;
         Paging.currentPage = currentPage;
         string url = "administrator/competitions/index";
         ViewBag.pagingString = Paging.GenerateLinkPaging(url);
         ViewBag.Title += " Competitions";
         return View(competitionsModels.ListCompetition((int)((currentPage - 1) * totalRecord), (int)totalRecord));
     }
     else
     {
         Session["errorContorllerAction"] = true;
         return Redirect("~/administrator");
     }
 }
 public ActionResult DesignCompetition(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);
             Competitions competitionsModels = new Competitions();
             competitionsModels.ID = idd;
             competitionsModels = competitionsModels.ListNavigation("Design");
             ViewBag.Title += " Designs of " + competitionsModels.Name + " Competition";
             List<Designs> listDesign = competitionsModels.Design.ToList();
             List<Designs> listDesignNew = new List<Designs>();
             listDesign.ForEach(delegate(Designs design)
             {
                 design = design.GetDesignByID();
                 listDesignNew.Add(design);
             });
             return View(listDesignNew);
         }
         catch
         {
             Session["admin"] = null;
             return Redirect("~/");
         }
     }
     else
     {
         Session["errorContorllerAction"] = true;
         return Redirect("~/administrator");
     }
 }
        public ActionResult Add(FormCollection form, HttpPostedFileBase Images)
        {
            int admin = base.Authentication();
            if (admin == 0)
            {
                return Redirect("~/member/logout");
            }
            else if (admin == 1)
            {
                base.LoadMenu();
                var db = new FineArtContext();
                ViewBag.listStaff = db.Members.Where(m => m.Role.ID == 3).ToList();
                ViewBag.listCOndition = db.Conditions.ToList();
                ViewBag.listAward = db.Awards.ToList();
                ViewBag.listKind = db.Kinds.ToList();
                if (form["submit_competition"] != null)
                {
                    StringBuilder stringBuilder = new StringBuilder();
                    stringBuilder.Append("<ul>");
                    Strings stringsLibs = new Strings();
                    if (form["Name"].Trim() == "")
                    {
                        stringBuilder.Append("<li>Please type competition name</li>");
                    }
                    if (form["Alias"].Trim() == "" || !Validator.ISAlias(form["Alias"]))
                    {
                        stringBuilder.Append("<li>Please type competition alias</li>");
                    }
                    else
                    {
                        try
                        {
                            string alias = form["Alias"].Trim().ToString();
                            var competition = db.Competitions.Where(c => c.Alias == alias).First();
                            stringBuilder.Append("<li>This competition alias had been exists in database, try a different</li>");
                        }
                        catch { }
                    }
                    int[] IDStaffs = stringsLibs.ListID(form["Staffs"]);
                    int[] IDConditions = stringsLibs.ListID(form["Conditions"]);
                    int[] IDAwards = stringsLibs.ListID(form["Awards"]);
                    int[] IDKinds = stringsLibs.ListID(form["Kinds"]);
                    ViewBag.IDStaffs = IDStaffs;
                    ViewBag.IDConditions = IDConditions;
                    ViewBag.IDAwards = IDAwards;
                    ViewBag.IDKinds = IDKinds;
                    ICollection<Members> listStaffs = db.Members.Where(s => IDStaffs.Contains(s.ID)).ToList();
                    ICollection<Conditions> listConditions = db.Conditions.Where(c => IDConditions.Contains(c.ID)).ToList();
                    List<Awards> listAwards = db.Awards.Where(a => IDAwards.Contains(a.ID)).ToList();
                    ICollection<Kinds> listKinds = db.Kinds.Where(k => IDKinds.Contains(k.ID)).ToList();
                    if (listStaffs.Count == 0)
                    {
                        stringBuilder.Append("<li>Please chose teachers scoring for this competition</li>");
                    }
                    if (listConditions.Count == 0)
                    {
                        stringBuilder.Append("<li>Please chose conditions for this competition</li>");
                    }
                    if (listAwards.Count == 0)
                    {
                        stringBuilder.Append("<li>Please chose awards for this competition</li>");
                    }
                    else
                    {
                        int j = listAwards.Count;
                        int i = 0;
                        int[] Levels = new int[j];
                        for (i = 0; i < j; i++)
                        {
                            Levels[i] = listAwards[i].Level;
                        }
                        for (i = 1; i <= j; i++)
                        {
                            if (!Levels.Contains(i))
                            {
                                stringBuilder.Append("<li>Please choose award for competition. Level of awards not duplicate</li>");
                                break;
                            }
                        }
                    }
                    if (listKinds.Count == 0)
                    {
                        stringBuilder.Append("<li>Please chose kinds for this competition</li>");
                    }
                    DateTime StartDate = new DateTime();
                    DateTime DeadlineDate = new DateTime();
                    DateTime EndDate = new DateTime();
                    try
                    {
                        StartDate = DateTime.Parse(form["StartDate"]);
                    }
                    catch
                    {
                        stringBuilder.Append("<li>Please type competition start date</li>");
                    }
                    try
                    {
                        DeadlineDate = DateTime.Parse(form["DeadlineDate"]);
                    }
                    catch
                    {
                        stringBuilder.Append("<li>Please type competition deadline date</li>");
                    }
                    try
                    {
                        EndDate = DateTime.Parse(form["EndDate"]);
                    }
                    catch
                    {
                        stringBuilder.Append("<li>Please type competition end date</li>");
                    }
                    try
                    {
                        if (DateTime.Parse(form["DeadlineDate"]) <= DateTime.Parse(form["StartDate"]))
                        {
                            stringBuilder.Append("<li>Deadline date should after start date</li>");
                        }
                    }
                    catch
                    {

                    }
                    try
                    {
                        if (DateTime.Parse(form["EndDate"]) <= DateTime.Parse(form["DeadlineDate"]))
                        {
                            stringBuilder.Append("<li>End date should after deadline date</li>");
                        }
                    }
                    catch
                    {

                    }

                    if (Images == null)
                    {
                        stringBuilder.Append("<li>Please chose a image for this competition</li>");
                    }
                    if (stringBuilder.ToString() == "<ul>")
                    {
                        ImagesClass objImageClass = new ImagesClass(Images);
                        string fileSaveName = Server.MapPath("~/Content/Images/competitions/" + form["Alias"] + ".jpg");
                        objImageClass.CreateNewImage(fileSaveName, 190, 190);
                        Competitions competitionsModels = new Competitions
                        {
                            Name = form["Name"],
                            Alias = form["Alias"],
                            Images = form["Alias"] + ".jpg",
                            Staffs = listStaffs,
                            Condition = listConditions,
                            Award = listAwards,
                            Kind = listKinds,
                            StartDate = StartDate,
                            DeadlineDate = DeadlineDate,
                            EndDate = EndDate,
                            Summary = form["Summary"].Trim()
                        };
                        db.Competitions.Add(competitionsModels);
                        db.SaveChanges();
                        ViewBag.success = "Add competition success!";
                    }
                    else
                    {
                        stringBuilder.Append("</ul>");
                        ViewBag.error = stringBuilder.ToString();
                        ViewBag.dataForm = form;
                    }
                }
                return View();
            }
            else
            {
                Session["errorContorllerAction"] = true;
                return Redirect("~/administrator");
            }
        }