/**
  * Controller: Menus
  * Action: Index
  * List All menu system
  * Author: Le Dang Son
  * Date: 08/08/2012
  */
 public ActionResult Index()
 {
     int admin = base.Authentication();
     if (admin == 0)
     {
         return Redirect("~/member/logout");
     }
     else if (admin == 1)
     {
         base.LoadMenu();
         List<Menus> listMenu = new FineArtContext().Menus.ToList();
         ViewBag.Title += " Menus";
         listMenu.ForEach(delegate(Menus menu)
         {
             if (menu.Controller == "")
             {
                 menu.Controller = "Index";
             }
             if (menu.Action == "")
             {
                 menu.Action = "Index";
             }
             Strings stringsLibs = new Strings();
             menu.Controller = stringsLibs.Capacital(menu.Controller);
             menu.Action = stringsLibs.Capacital(menu.Action);
         });
         ViewBag.listMenu = listMenu;
         return View();
     }
     else
     {
         Session["errorContorllerAction"] = true;
         return Redirect("~/administrator");
     }
 }
 public virtual ActionResult Kind()
 {
     var db = new FineArtContext();
     var kinds = db.Kinds.ToList();
     ViewBag.kind = kinds;
     return PartialView();
 }
        /**
         * Controller: Index
         * Action: Index
         * Load Administrator Index page
         * Author: Le Dang Son
         * Date: 09/08/2012
         */
        public ActionResult Index()
        {
            int admin = base.Authentication();
            if (admin == 0)
            {
                return Redirect("~/member/logout");
            }
            else if (admin == 1)
            {
                base.LoadMenu();
                ViewBag.Title += " Home";
                var db = new FineArtContext();
                ViewBag.totalCompetition = db.Competitions.Count();
                ViewBag.totalDesign = db.Designs.Count();
                ViewBag.totalKind = db.Kinds.Count();
                ViewBag.totalExhibition = db.Exhibitions.Count();
                ViewBag.totalMember = db.Members.Count();

                ViewBag.newDesign = db.Designs.Include("Member").OrderBy(d => d.DatePost).Skip(0).Take(4);
                return View();
            }
            else
            {
                Session["errorContorllerAction"] = true;
                return Redirect("~/administrator");
            }
        }
        public ActionResult Add(FormCollection form)
        {
            int admin = base.Authentication();
            if (admin == 0)
            {
                return Redirect("~/member/logout");
            }
            else if (admin == 1)
            {
                base.LoadMenu();
                var db = new FineArtContext();
                if (form["submit_class"] != null)
                {
                    StringBuilder stringBuilder = new StringBuilder();
                    stringBuilder.Append("<ul>");
                    Strings stringsLibs = new Strings();
                    if (form["Name"].Trim() == "")
                    {
                        stringBuilder.Append("<li>Please type class name</li>");
                    }
                    if (form["Alias"].Trim() == "")
                    {
                        stringBuilder.Append("<li>Please type class alias</li>");
                    }
                    else
                    {
                        try
                        {
                            string alias = form["Alias"].Trim().ToString();
                            var classModels = db.Classes.Where(c => c.Alias == alias).First();
                            stringBuilder.Append("<li>This class alias had been exists in database, try a different</li>");
                        }
                        catch { }
                    }

                    if (stringBuilder.ToString() == "<ul>")
                    {
                        Classes classModels = new Classes { Name = form["Name"], Alias = form["Alias"], DateUpdate = DateTime.Now };
                        db.Classes.Add(classModels);
                        db.SaveChanges();
                        ViewBag.success = "Add class success!";
                    }
                    else
                    {
                        stringBuilder.Append("</ul>");
                        ViewBag.error = stringBuilder.ToString();
                        ViewBag.dataForm = form;
                    }
                }
                return View();
            }
            else
            {
                Session["errorContorllerAction"] = true;
                return Redirect("~/administrator");
            }
        }
 /**
  * Function: GetRoleWithID
  * List Menu through Role ID
  * @returns: Roles and list Menus
  * Author: Le Dang Son
  * Date: 06/08/2012
  */
 public Roles GetRoleWithID()
 {
     Roles roles = new Roles();
     using (var db = new FineArtContext())
     {
         roles = (Roles)db.Roles.Include("menu").Where(r => r.ID == this.ID).FirstOrDefault();
     }
     return roles;
 }
 /**
  * Function: GetMemberByUserAndPass
  * Get Member by username and password
  * @param name="pass": password
  * @param name="user": username
  * @returns: A member
  * Author: Le Dang Son
  * Date: 06/08/2012
  */
 public Members GetMemberByUserAndPass(string user, string pass)
 {
     FineArtContext context = new FineArtContext();
     //var query = (from d in context.Members
                  //where d.Username == user && d.Password == pass
                  //select d).FirstOrDefault();
     var query = context.Members.Include("Role").Where(m => m.Username == user && m.Password == pass).FirstOrDefault();
     return query;
 }
 public List<Designs> ListDesign(int skip, int take)
 {
     var db = new FineArtContext();
     return db.Designs
         .Include("Member")
         .Include("Kind")
         .Include("Competition")
         .OrderBy(d => d.ID).Skip(skip).Take(take).ToList();
 }
 public ActionResult Detail(string id)
 {
     base.Authentication();
     if (id != null && Validator.ISAlias(id))
     {
         var db = new FineArtContext();
         var exhibition = db.Exhibitions.Where(e => e.Alias == id).First();
         return View(exhibition);
     }
     else
     {
         return Redirect("~/");
     }
 }
 public ActionResult Detail(string id)
 {
     base.Authentication();
     if (id != null && Validator.ISAlias(id))
     {
         var db = new FineArtContext();
         var upcomming = db.Competitions.Include("Condition").Include("Award").Include("Staffs").Include("Design").Single(g => g.Alias == id);
         ViewBag.Title = "Competition: " + upcomming.Name;
         return View(upcomming);
     }
     else
     {
         return Redirect("~/error");
     }
 }
        // list upcomming with items
        public ActionResult Index()
        {

            base.Authentication();
            
            if (Session["user-loged"] != null && Session["user-loged"].ToString() != "")
            {
                var db = new FineArtContext();
                var upcomming = db.Competitions.Where(s => s.StartDate > DateTime.Now).ToList();
                ViewBag.upcomming = upcomming;

                var oncomming = db.Competitions.Include("Design")
                                  .Where(p => p.StartDate < DateTime.Now && p.EndDate >= DateTime.Now)
                                  .ToList();
                ViewBag.oncomming = oncomming;

                var competition = db.Competitions.Include("Award")
                    .Where(c => c.EndDate < DateTime.Now)
                    .OrderByDescending(c => c.EndDate)
                    .Take(1).First();
                var studentaward = db.Marks
                   .Join(db.Members, mark => mark.Design.Member.ID, member => member.ID, (mark, member) => new { Member = member, Mark = mark })
                   .Where(a => a.Mark.Design.Competition.ID == competition.ID)
                   .GroupBy(b => b.Mark.Design)
                   .OrderByDescending(c => c.Average(z => z.Mark.Mark))
                   .ThenBy(c => c.Key.DatePost)
                   .Take(competition.Award.Count)
                   .ToList();
                List<MemberAward> listMemberAward = new List<MemberAward>();
                MemberAward memberAward;
                foreach (var item in studentaward)
                {
                    memberAward = new MemberAward();
                    memberAward.ID = item.Key.Member.ID;
                    memberAward.Name = item.Key.Member.Name;
                    memberAward.Image = item.Key.Member.Images;
                    memberAward.Mark = item.Average(m => m.Mark.Mark).ToString();
                    memberAward.Design = item.Key;
                    listMemberAward.Add(memberAward);
                }
                ViewBag.listMemberAward = listMemberAward;
                return View(upcomming);
            }
            else
            {
                return Redirect("~/member");
            }
        }
 public virtual ActionResult Profile()
 {
     try
     {
         string username = Session["user-loged"].ToString();
         var db = new FineArtContext();
         var member = db.Members.Include("Role").Where(m => m.Username == username).First();
         var menus = db.Menus.Include("Role").Where(m => m.Role.Any(r => r.ID == member.Role.ID)).ToList();
         if (menus.Count > 0)
         {
             ViewBag.gotoAdmin = true;
         }
         return PartialView(member);
     }
     catch
     {
         return Redirect("~/member");
     }
 }
        //
        // GET: /Exhibition/

        public ActionResult Index(string id)
        {
            base.Authentication();
            var db = new FineArtContext();
            int currentPage = Paging.GetPage(id);
            decimal totalRecord = GlobalInfo.NumberRecordInPage;
            decimal totalExhibition = db.Exhibitions.Count();
            int totalPage = (int)Math.Ceiling(Convert.ToDecimal(totalExhibition / totalRecord));
            if (currentPage > totalPage)
            {
                currentPage = totalPage;
            }
            Paging.numPage = totalPage;
            Paging.numLinkDisplay = GlobalInfo.NumLinkPagingDisplay;
            Paging.currentPage = currentPage;
            var exhibition = db.Exhibitions
                .OrderBy(o => o.StartDate)
                .Skip((int)((currentPage - 1) * totalRecord))
                .Take((int)totalRecord)
                .ToList();
            ViewBag.pagingString = Paging.GenerateLinkPaging("exhibition/index");
            return View(exhibition);
        }
        //
        // GET: /Designs/

        public ActionResult Index(string id)
        {
            base.Authentication();
            var db = new FineArtContext();
            int currentPage = Paging.GetPage(id);
            decimal totalRecord = GlobalInfo.NumberRecordInPage;
            decimal totalDesign = db.Designs.Count();
            int totalPage = (int)Math.Ceiling(Convert.ToDecimal(totalDesign / totalRecord));
            if (currentPage > totalPage)
            {
                currentPage = totalPage;
            }
            Paging.numPage = totalPage;
            Paging.numLinkDisplay = GlobalInfo.NumLinkPagingDisplay;
            Paging.currentPage = currentPage;
            var design = db.Designs.Include("Member").Include("Kind").Include("Competition")
                              .OrderBy(p => p.ID)
                              .Skip((int)((currentPage - 1) * totalRecord))
                              .Take((int)totalRecord)
                              .ToList();
            ViewBag.pagingString = Paging.GenerateLinkPaging("design/index");
            return View(design);
        }
 /**
  * Function: Authentication
  * Check role by username
  * If is admin or manager or staff, continues else redirect to home page
  * Author: Le Dang Son
  * Date: 06/08/2012
  */
 public int Authentication()
 {
     if (Session["admin"] != null)
     {
         Members member = (Members)Session["admin"];
         if (member.Name != null && member.Name != "" && member.Role.ID < 4)
         {
             ViewBag.Name = member.Name;
             Menus menusModels = new Menus();
             menusModels.Controller = RouteData.Values["controller"].ToString().ToLower();
             menusModels.Action = RouteData.Values["action"].ToString().ToLower();
             var db = new FineArtContext();
             var query = db.Menus.Include("Role")
                 .Where(m => m.Controller == ((menusModels.Controller == "index") ? "" : menusModels.Controller)
                     && m.Action == ((menusModels.Action == "index") ? "" : menusModels.Action))
                     .FirstOrDefault();
             var role = query.Role.Where(r => r.ID == member.Role.ID).FirstOrDefault();
             if (role == null)
             {
                 return 2;
             }
             else
             {
                 return 1;
             }
         }
         else
         {
             return 0;
         }
     }
     else
     {
         return 0;
     }
 }
 public ActionResult Add(FormCollection form)
 {
     int admin = base.Authentication();
     if (admin == 0)
     {
         return Redirect("~/member/logout");
     }
     else if (admin == 1)
     {
         base.LoadMenu();
         var db = new FineArtContext();
         if (form["submit_condition"] != null)
         {
             StringBuilder stringBuilder = new StringBuilder();
             stringBuilder.Append("<ul>");
             Strings stringsLibs = new Strings();
             if (form["Name"].Trim() == "")
             {
                 stringBuilder.Append("<li>Please type condition name</li>");
             }
             if (form["Description"].Trim() == "")
             {
                 stringBuilder.Append("<li>Please type condition description</li>");
             }
             if (stringBuilder.ToString() == "<ul>")
             {
                 Conditions condition = new Conditions { Name = form["Name"], DateUpdate = DateTime.Now, Description = form["Description"].Trim() };
                 db.Conditions.Add(condition);
                 db.SaveChanges();
                 ViewBag.success = "Add condition success!";
             }
             else
             {
                 stringBuilder.Append("</ul>");
                 ViewBag.error = stringBuilder.ToString();
                 ViewBag.dataForm = form;
             }
         }
         return View();
     }
     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");
            }
        }
 public ActionResult Delete(string id)
 {
     int admin = base.Authentication();
     if (admin == 0)
     {
         return Redirect("~/member/logout");
     }
     else if (admin == 1)
     {
         try
         {
             int idd = Convert.ToInt16(id);
             if (idd != 1)
             {
                 var db = new FineArtContext();
                 var role = db.Roles.Where(r => r.ID == idd).First();
                 var members = db.Members.Where(m => m.Role.ID == role.ID).ToList();
                 members.ForEach(delegate(Members member)
                 {
                     member.Role = null;
                     db.SaveChanges();
                 });
                 db.Roles.Remove(role);
                 db.SaveChanges();
             }
             return Redirect("~/administrator/roles/");
         }
         catch
         {
             return Redirect("~/");
         }
     }
     else
     {
         Session["errorContorllerAction"] = true;
         return Redirect("~/administrator");
     }
 }
        public ActionResult Edit(string id, FormCollection form, HttpPostedFileBase Images)
        {
            int admin = base.Authentication();
            if (admin == 0)
            {
                return Redirect("~/member/logout");
            }
            else if (admin == 1)
            {
                base.LoadMenu();
                try
                {
                    int idd = Convert.ToInt16(id);
                    var db = new FineArtContext();
                    ICollection<Members> listStaffs;
                    ICollection<Conditions> listConditions;
                    List<Awards> listAwards;
                    ICollection<Kinds> listKinds;
                    int[] IDStaffs;
                    int[] IDConditions;
                    int[] IDAwards;
                    int[] IDKinds;

                    Competitions competiton = db.Competitions.Include("Staffs").Include("Condition").Include("Award").Include("Kind").Where(c => c.ID == idd && c.DeadlineDate > DateTime.Now).FirstOrDefault();
                    if (competiton == null)
                    {
                        Session["error"] = "This competition has finished.";
                        return Redirect("~/administrator/competitions/");
                    }
                    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)
                    {
                        form["Name"] = competiton.Name;
                        form["Alias"] = competiton.Alias;
                        form["StartDate"] = competiton.StartDate.ToString("dd/MM/yyyy");
                        form["DeadlineDate"] = competiton.DeadlineDate.ToString("dd/MM/yyyy"); ;
                        form["EndDate"] = competiton.EndDate.ToString("dd/MM/yyyy");
                        form["Summary"] = competiton.Summary;
                        ViewBag.dataForm = form;

                        listStaffs = competiton.Staffs;
                        listConditions = competiton.Condition;
                        listAwards = competiton.Award.ToList();
                        listKinds = competiton.Kind;
                        IDStaffs = new int[listStaffs.Count];
                        IDConditions = new int[listConditions.Count];
                        IDAwards = new int[listAwards.Count];
                        IDKinds = new int[listKinds.Count];
                        int i = 0;
                        foreach (Members member in listStaffs)
                        {
                            IDStaffs[i] = member.ID;
                            i++;
                        }
                        i = 0;
                        foreach (Conditions condition in listConditions)
                        {
                            IDConditions[i] = condition.ID;
                            i++;
                        }
                        i = 0;
                        foreach (Awards award in listAwards)
                        {
                            IDAwards[i] = award.ID;
                            i++;
                        }
                        i = 0;
                        foreach (Kinds kind in listKinds)
                        {
                            IDKinds[i] = kind.ID;
                            i++;
                        }

                        ViewBag.IDStaffs = IDStaffs;
                        ViewBag.IDConditions = IDConditions;
                        ViewBag.IDAwards = IDAwards;
                        ViewBag.IDKinds = IDKinds;
                    }
                    else
                    {
                        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() == "")
                        {
                            stringBuilder.Append("<li>Please type competition alias</li>");
                        }
                        else
                        {
                            if (form["Alias"].Trim() != competiton.Alias)
                            {
                                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 { }
                            }
                        }
                        IDStaffs = stringsLibs.ListID(form["Staffs"]);
                        IDConditions = stringsLibs.ListID(form["Conditions"]);
                        IDAwards = stringsLibs.ListID(form["Awards"]);
                        IDKinds = stringsLibs.ListID(form["Kinds"]);
                        ViewBag.IDStaffs = IDStaffs;
                        ViewBag.IDConditions = IDConditions;
                        ViewBag.IDAwards = IDAwards;
                        ViewBag.IDKinds = IDKinds;
                        listStaffs = db.Members.Where(s => IDStaffs.Contains(s.ID)).ToList();
                        listConditions = db.Conditions.Where(c => IDConditions.Contains(c.ID)).ToList();
                        listAwards = db.Awards.Where(a => IDAwards.Contains(a.ID)).ToList();
                        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 deadline 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 (stringBuilder.ToString() == "<ul>")
                        {
                            if (Images != null)
                            {
                                string fileOldName = Server.MapPath("~/Content/Images/competitions/" + competiton.Images);
                                FilesClass.DeleteFile(fileOldName);
                                ImagesClass objImageClass = new ImagesClass(Images);
                                string fileSaveName = Server.MapPath("~/Content/Images/competitions/" + form["Alias"] + ".jpg");
                                objImageClass.CreateNewImage(fileSaveName, 190, 190);
                            }
                            else
                            {
                                if (form["Alias"].Trim() != competiton.Alias)
                                {
                                    string fileOldName = Server.MapPath("~/Content/Images/competitions/" + competiton.Alias + ".jpg");
                                    string fileNewName = Server.MapPath("~/Content/Images/competitions/" + form["Alias"] + ".jpg");
                                    FilesClass.RenameFile(fileOldName, fileNewName);
                                }
                            }
                            Competitions competitonsModels;
                            competitonsModels = db.Competitions.Where(c => c.ID == idd).FirstOrDefault();
                            competitonsModels.Name = form["Name"];
                            competitonsModels.Alias = form["Alias"];
                            competitonsModels.Images = form["Alias"] + ".jpg";
                            competitonsModels.StartDate = StartDate;
                            competitonsModels.DeadlineDate = DeadlineDate;
                            competitonsModels.EndDate = EndDate;
                            competitonsModels.Staffs = listStaffs;
                            competitonsModels.Condition = listConditions;
                            competitonsModels.Award = listAwards;
                            competitonsModels.Kind = listKinds;
                            competitonsModels.Summary = form["Summary"].Trim();
                            ViewBag.dataForm = form;
                            ViewBag.success = "Update competition success!";
                            db.SaveChanges();
                        }
                        else
                        {
                            stringBuilder.Append("</ul>");
                            ViewBag.error = stringBuilder.ToString();
                            ViewBag.dataForm = form;
                        }
                    }

                    return View();
                }
                catch
                {
                    Session["admin"] = null;
                    return Redirect("~/");
                }
            }
            else
            {
                Session["errorContorllerAction"] = true;
                return Redirect("~/administrator");
            }
        }
        public ActionResult Delete(string id)
        {
            int admin = base.Authentication();
            if (admin == 0)
            {
                return Redirect("~/member/logout");
            }
            else if (admin == 1)
            {
                try
                {
                    int idd = Convert.ToInt16(id);
                    var db = new FineArtContext();
                    var competitionsModels = db.Competitions.Include("Design").Where(c => c.ID == idd).FirstOrDefault();
                    var listDesign = competitionsModels.Design.ToList();
                    listDesign.ForEach(delegate(Designs ds)
                    {
                        var listMark = db.Marks.Where(m => m.Design.ID == ds.ID).ToList();
                        listMark.ForEach(delegate(Marks mk)
                        {
                            db.Marks.Remove(mk);
                        });
                        var listCustomer = db.Customers.Where(c => c.Design.ID == ds.ID).ToList();
                        listCustomer.ForEach(delegate(Customers cus)
                        {
                            db.Customers.Remove(cus);
                        });
                        db.Designs.Remove(ds);
                    });
                    db.Competitions.Remove(competitionsModels);
                    db.SaveChanges();
                    return Redirect("~/administrator/competitions/");
                }
                catch
                {
                    Session["admin"] = null;
                    return Redirect("~/");
                }
            }
            else
            {
                Session["errorContorllerAction"] = true;
                return Redirect("~/administrator");
            }

        }
        public ActionResult Add(FormCollection form)
        {
            int admin = base.Authentication();
            if (admin == 0)
            {
                return Redirect("~/member/logout");
            }
            else if (admin == 1)
            {
                base.LoadMenu();
                var db = new FineArtContext();
                ViewBag.listMenu = db.Menus.ToList();
                if (form["submit_role"] != null)
                {
                    StringBuilder stringBuilder = new StringBuilder();
                    stringBuilder.Append("<ul>");
                    Strings stringsLibs = new Strings();
                    if (form["Name"].Trim() == "")
                    {
                        stringBuilder.Append("<li>Please type role name</li>");
                    }
                    if (form["Alias"].Trim() == "" || !Validator.ISAlias(form["Alias"]))
                    {
                        stringBuilder.Append("<li>Please type role alias</li>");
                    }
                    else
                    {
                        try
                        {
                            string alias = form["Alias"].Trim().ToString();
                            var role = db.Roles.Where(c => c.Alias == alias).First();
                            stringBuilder.Append("<li>This role alias had been exists in database, try a different</li>");
                        }
                        catch { }
                    }
                    int[] IDMenus = stringsLibs.ListID(form["Menus"]);
                    ViewBag.IDMenus = IDMenus;
                    ICollection<Menus> listMenus = db.Menus.Where(s => IDMenus.Contains(s.ID)).ToList();
                    if (stringBuilder.ToString() == "<ul>")
                    {
                        Roles roles = new Roles
                        {
                            Name = form["Name"].Trim(),
                            Alias = form["Alias"].Trim(),
                            Description = form["Description"].Trim(),
                            Menu = listMenus
                        };
                        db.Roles.Add(roles);
                        db.SaveChanges();
                        ViewBag.success = "Add role success!";
                    }
                    else
                    {
                        stringBuilder.Append("</ul>");
                        ViewBag.error = stringBuilder.ToString();
                        ViewBag.dataForm = form;
                    }
                }

                return View();
            }
            else
            {
                Session["errorContorllerAction"] = true;
                return Redirect("~/administrator");
            }
        }
 public ActionResult Edit(string id, FormCollection form)
 {
     int admin = base.Authentication();
     if (admin == 0)
     {
         return Redirect("~/member/logout");
     }
     else if (admin == 1)
     {
         var db = new FineArtContext();
         base.LoadMenu();
         try
         {
             int idd = Convert.ToInt16(id);
             Classes classModels = db.Classes.Where(c => c.ID == idd).FirstOrDefault();
             if (form["submit_class"] == null)
             {
                 form["Name"] = classModels.Name;
                 form["Alias"] = classModels.Alias;
                 ViewBag.dataForm = form;
             }
             else
             {
                 StringBuilder stringBuilder = new StringBuilder();
                 stringBuilder.Append("<ul>");
                 Strings stringsLibs = new Strings();
                 if (form["Name"].Trim() == "")
                 {
                     stringBuilder.Append("<li>Please type class name</li>");
                 }
                 if (form["Alias"].Trim() == "")
                 {
                     stringBuilder.Append("<li>Please type class alias</li>");
                 }
                 else if (form["Alias"] != classModels.Alias)
                 {
                     try
                     {
                         string alias = form["Alias"].Trim().ToString();
                         var classes = db.Classes.Where(c => c.Alias == alias).First();
                         stringBuilder.Append("<li>This class alias had been exists in database, try a different</li>");
                     }
                     catch { }
                 }
                 if (stringBuilder.ToString() == "<ul>")
                 {
                     classModels.Name = form["Name"];
                     classModels.Alias = form["Alias"];
                     db.SaveChanges();
                     ViewBag.dataForm = form;
                     ViewBag.success = "Update class success!";
                 }
                 else
                 {
                     stringBuilder.Append("</ul>");
                     ViewBag.error = stringBuilder.ToString();
                     ViewBag.dataForm = form;
                 }
             }
             return View();
         }
         catch
         {
             Session["admin"] = null;
             return Redirect("~/");
         }
     }
     else
     {
         Session["errorContorllerAction"] = true;
         return Redirect("~/administrator");
     }
 }
 public ActionResult Delete(string id)
 {
     base.Authentication();
     try
     {
         if (id != null && Validator.ISAlias(id))
         {
             var db = new FineArtContext();
             string username = Session["user-loged"].ToString();
             var design = db.Designs.Where(d => d.Alias == id && d.Member.Username == username).First();
             var customer = db.Customers.Where(c => c.Design.ID == design.ID).ToList();
             customer.ForEach(delegate(Customers cust)
             {
                 cust.Design = null;
             });
             var mark = db.Marks.Where(m => m.Design.ID == design.ID).ToList();
             mark.ForEach(delegate(Marks markItem)
             {
                 db.Marks.Remove(markItem);
             });
             db.SaveChanges();
             db.Designs.Remove(design);
             db.SaveChanges();
             return Redirect("~/member/profile");
         }
         else
         {
             return Redirect("~/");
         }
     }
     catch
     {
         return Redirect("~/");
     }
 }
 public ActionResult Search(string id)
 {
     base.Authentication();
     if (id != null)
     {
         var db = new FineArtContext();
         string[] txtSearch = id.Split('-');
         List<Designs> listDesigns = new List<Designs>();
         int i = 0;
         for (i = 0; i < txtSearch.Length; i++)
         {
             string searchTxt = txtSearch[i];
             var designs = db.Designs.Where(d => d.Name.Contains(searchTxt)).ToList();
             if (designs.Count > 0)
             {
                 designs.ForEach(delegate(Designs des)
                 {
                     listDesigns.Add(des);
                 });
             }
         }
         listDesigns = listDesigns.Distinct().ToList();
         return View(listDesigns);
     }
     else
     {
         return Redirect("~/design");
     }
 }
 public ActionResult Delete(string id)
 {
     int admin = base.Authentication();
     if (admin == 0)
     {
         return Redirect("~/member/logout");
     }
     else if (admin == 1)
     {
         try
         {
             int idd = Convert.ToInt16(id);
             var db = new FineArtContext();
             Conditions condition = db.Conditions.Where(c => c.ID == idd).First();
             db.Conditions.Remove(condition);
             db.SaveChanges();
             return Redirect("~/administrator/conditions/");
         }
         catch
         {
             Session["admin"] = null;
             return Redirect("~/");
         }
     }
     else
     {
         Session["errorContorllerAction"] = true;
         return Redirect("~/administrator");
     }
 }
 public ActionResult AddConditionsCompetition(string id, FormCollection form)
 {
     int admin = base.Authentication();
     if (admin == 0)
     {
         return Redirect("~/member/logout");
     }
     else if (admin == 1)
     {
         base.LoadMenu();
         try
         {
             int competitionID = Convert.ToInt16(id);
             ViewBag.competitionID = competitionID;
             var db = new FineArtContext();
             var competition = db.Competitions.Include("Condition").Where(c => c.ID == competitionID && c.DeadlineDate > DateTime.Now).FirstOrDefault();
             if (competition == null)
             {
                 Session["error"] = "This competition had ended.";
                 return Redirect("~/administrator/conditions/conditioncompetition/" + competitionID);
             }
             else
             {
                 if (form["submit_condition"] == null)
                 {
                     var conditions = competition.Condition.ToList();
                     var conditionsOther = db.Conditions.ToList();
                     conditionsOther = conditionsOther.Except(conditions).ToList();
                     ViewBag.listConditions = conditionsOther;
                     return View();
                 }
                 else
                 {
                     int[] IDConditions = new Strings().ListID(form["Conditions"]);
                     List<Conditions> listCondition = db.Conditions.Where(c => IDConditions.Contains(c.ID)).ToList();
                     listCondition.ForEach(delegate(Conditions condition)
                     {
                         competition.Condition.Add(condition);
                     });
                     db.SaveChanges();
                     return Redirect("~/administrator/conditions/addconditionscompetition/" + competitionID);
                 }
             }
         }
         catch
         {
             return Redirect("~/");
         }
     }
     else
     {
         Session["errorContorllerAction"] = true;
         return Redirect("~/administrator");
     }
 }
 public ActionResult Competition(string id, string param)
 {
     base.Authentication();
     try
     {
         if (id != null && Validator.ISAlias(id))
         {
             var db = new FineArtContext();
             int currentPage = Paging.GetPage(param);
             decimal totalRecord = GlobalInfo.NumberRecordInPage;
             var competition = db.Competitions.Include("Design")
                 .Where(k => k.Alias == id)
                 .Single();
             decimal totalDesign = competition.Design.Count;
             int totalPage = (int)Math.Ceiling(Convert.ToDecimal(totalDesign / totalRecord));
             if (currentPage > totalPage)
             {
                 currentPage = totalPage;
             }
             var designs = competition.Design
                 .Join(db.Members, d => d.Member.ID, m => m.ID, (Design, Member) => new { Design = Design, Member = Member })
                 .OrderBy(p => p.Design.ID)
                 .Skip((int)((currentPage - 1) * totalRecord))
                 .Take((int)totalRecord)
                 .ToList();
             List<DesignsKind> listDesign = new List<DesignsKind>();
             DesignsKind designKind;
             foreach (var item in designs)
             {
                 designKind = new DesignsKind { Design = item.Design, Member = item.Member };
                 listDesign.Add(designKind);
             }
             Paging.numPage = totalPage;
             Paging.numLinkDisplay = GlobalInfo.NumLinkPagingDisplay;
             Paging.currentPage = currentPage;
             ViewBag.pagingString = Paging.GenerateLinkPaging("design/competition/" + id);
             ViewBag.Title = competition.Name;
             return View(listDesign);
         }
         else
         {
             return Redirect("~/");
         }
     }
     catch
     {
         return Redirect("~/");
     }
 }
 public ActionResult Edit(string id, FormCollection form)
 {
     int admin = base.Authentication();
     if (admin == 0)
     {
         return Redirect("~/member/logout");
     }
     else if (admin == 1)
     {
         base.LoadMenu();
         var db = new FineArtContext();
         try
         {
             int idd = Convert.ToInt16(id);
             Conditions condition = db.Conditions.Where(c => c.ID == idd).FirstOrDefault();
             if (form["submit_condition"] == null)
             {
                 form["Name"] = condition.Name;
                 form["Description"] = condition.Description;
                 ViewBag.dataForm = form;
             }
             else
             {
                 StringBuilder stringBuilder = new StringBuilder();
                 stringBuilder.Append("<ul>");
                 Strings stringsLibs = new Strings();
                 if (form["Name"].Trim() == "")
                 {
                     stringBuilder.Append("<li>Please type condition name</li>");
                 }
                 if (form["Description"].Trim() == "")
                 {
                     stringBuilder.Append("<li>Please type condition description</li>");
                 }
                 if (stringBuilder.ToString() == "<ul>")
                 {
                     condition.Name = form["Name"];
                     condition.Description = form["Description"].Trim();
                     db.SaveChanges();
                     ViewBag.dataForm = form;
                     ViewBag.success = "Update condition success!";
                 }
                 else
                 {
                     stringBuilder.Append("</ul>");
                     ViewBag.error = stringBuilder.ToString();
                     ViewBag.dataForm = form;
                 }
             }
             return View();
         }
         catch
         {
             Session["admin"] = null;
             return Redirect("~/");
         }
     }
     else
     {
         Session["errorContorllerAction"] = true;
         return Redirect("~/administrator");
     }
 }
        public ActionResult Edit(string id, FormCollection form, HttpPostedFileBase Images)
        {
            base.Authentication();
            if (id != null && Validator.ISAlias(id))
            {
                var db = new FineArtContext();
                string username = Session["user-loged"].ToString();
                var design = db.Designs
                    .Include("Competition")
                    .Include("Member")
                    .Include("Kind")
                    .Where(a => a.Alias == id && a.Competition.DeadlineDate > DateTime.Now && a.Member.Username == username)
                    .First();

                bool IsSold = false;
                decimal PriceSold = 0;
                bool IsPaidStudent = false;
                Competitions competition = db.Competitions
                    .Include("Award")
                    .Include("Condition")
                    .Include("Kind")
                    .Where(c => c.ID == design.Competition.ID).First();
                if (form["submit_design"] == null)
                {
                    form["Name"] = design.Name;
                    form["Alias"] = design.Alias;
                    form["Description"] = design.Description;
                    form["Kind"] = design.Kind.ID.ToString();
                    if (design.IsSold)
                    {
                        form["IsSold"] = "on";
                    }
                    if (design.IsPaidStudent)
                    {
                        form["IsPaidStudent"] = "on";
                    }
                    if (design.PriceSold != 0)
                    {
                        form["PriceSold"] = design.PriceSold.ToString();
                    }
                    ViewBag.dataForm = form;
                }
                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
                    {
                        if (design.Alias != form["Alias"].Trim())
                        {
                            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 (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
                    {
                        if (Images != null)
                        {
                            string fileOldName = Server.MapPath("~/Content/Images/designs/thumbnails/" + design.Images);
                            FilesClass.DeleteFile(fileOldName);
                            fileOldName = Server.MapPath("~/Content/Images/designs/bigimages/" + design.Images);
                            FilesClass.DeleteFile(fileOldName);
                            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);
                        }
                        else
                        {
                            if (design.Alias != form["Alias"].Trim())
                            {
                                string path = "~/Content/Images/designs/";
                                string fileOldName = Server.MapPath(path + "thumbnails/" + design.Images);
                                string fileNewName = Server.MapPath(path + "thumbnails/" + form["Alias"] + ".jpg");
                                FilesClass.RenameFile(fileOldName, fileNewName);
                                fileOldName = Server.MapPath(path + "bigimages/" + design.Images);
                                fileNewName = Server.MapPath(path + "bigimages/" + form["Alias"] + ".jpg");
                                FilesClass.RenameFile(fileOldName, fileNewName);
                            }
                        }
                        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;
                        }
                        design.Name = form["Name"].Trim();
                        design.Alias = form["Alias"].Trim();
                        design.Images = form["Alias"].Trim() + ".jpg";
                        design.DatePost = DateTime.Now;
                        design.Description = form["Description"].Trim();
                        design.IsSold = IsSold;
                        design.IsPaidStudent = IsPaidStudent;
                        design.PriceSold = PriceSold;
                        design.Kind = kind;
                        db.SaveChanges();
                        ViewBag.designAlias = form["Alias"].Trim();
                        Session["success"] = form["Alias"];
                        return Redirect("~/design/edit/" + form["Alias"] +"#submition");
                    }
                }
                return View(competition);
            }
            else
            {
                return null;
            }
        }
 public ActionResult RemoveConditionCompetition(string id, string param)
 {
     int admin = base.Authentication();
     if (admin == 0)
     {
         return Redirect("~/member/logout");
     }
     else if (admin == 1)
     {
         try
         {
             var db = new FineArtContext();
             int conditionID = Convert.ToInt16(id);
             int competitionID = Convert.ToInt16(param);
             var competition = db.Competitions.Where(c => c.ID == competitionID && c.DeadlineDate > DateTime.Now).First();
             if (competition == null)
             {
                 Session["error"] = "This competition had ended.";
                 return Redirect("~/administrator/conditions/conditioncompetition/" + competitionID);
             }
             else
             {
                 var condition = db.Conditions.Where(c => c.ID == conditionID).First();
                 competition.Condition.Remove(condition);
                 db.SaveChanges();
                 return Redirect("~/administrator/conditions/conditioncompetition/" + competitionID);
             }
         }
         catch
         {
             return Redirect("~/");
         }
     }
     else
     {
         Session["errorContorllerAction"] = true;
         return Redirect("~/administrator");
     }
 }
 public ActionResult Detail(string id,FormCollection form)
 {
     base.Authentication();
     if (id != null && Validator.ISAlias(id))
     {
         var db = new FineArtContext();
         var design = db.Designs.Include("Member").Include("Competition").Include("Kind").Single(g => g.Alias == id);
         var markDesign = db.Marks.Include("Staff").Where(m => m.Design.ID == design.ID).ToList();
         if (markDesign.Count > 0)
         {
             ViewBag.mark = markDesign.Average(m => m.Mark);
         }
         else
         {
             ViewBag.mark = "Not set";
         }
         ViewBag.markDesign = markDesign;
         string username = Session["user-loged"].ToString();
         Members member = db.Members.Where(m => m.Username == username).FirstOrDefault();
         if (member != null)
         {
             var competition = db.Competitions.Include("Staffs").Where(c => c.ID == design.Competition.ID && c.EndDate > DateTime.Now).FirstOrDefault();
             if (competition != null)
             {
                 var mem = competition.Staffs.Where(s => s.ID == member.ID).FirstOrDefault();
                 if (mem != null)
                 {
                     ViewBag.isStaff = true;
                     if (form["submit_mark"] != null)
                     {
                         StringBuilder stringBuilder = new StringBuilder();
                         stringBuilder.Append("<ul>");
                         if (form["mark"] == null || Convert.ToInt16(form["mark"]) < 1 || Convert.ToInt16(form["mark"]) > 5)
                         {
                             stringBuilder.Append("<li>Please choose mark for this design.</li>");
                         }
                         if (stringBuilder.ToString() != "<ul>")
                         {
                             stringBuilder.Append("</ul>");
                             ViewBag.error = stringBuilder.ToString();
                             ViewBag.dataForm = form;
                         }
                         else
                         {
                             var mark = db.Marks.Where(m => m.Staff.ID == member.ID && m.Design.ID == design.ID).FirstOrDefault();
                             if (mark != null)
                             {
                                 mark.Mark = Convert.ToInt16(form["mark"]);
                                 mark.ReMark = form["remark"].Trim();
                                 db.SaveChanges();
                             }
                             else
                             {
                                 mark = new Marks
                                 {
                                     Mark = Convert.ToInt16(form["mark"]),
                                     ReMark = form["remark"].Trim(),
                                     Design = design,
                                     Staff = member,
                                 };
                                 db.Marks.Add(mark);
                                 db.SaveChanges();
                             }
                             ViewBag.success = true;
                         }
                     }
                 }
             }
         }
         return View(design);
     }
     else
     {
         return Redirect("~/");
     }
 }