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 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");
            }
        }
コード例 #3
0
        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;
            }
        }
コード例 #4
0
        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();
                    Exhibitions exhibition = db.Exhibitions.Where(c => c.ID == idd).First();
                    if (form["submit_exhibition"] == null)
                    {
                        form["Name"] = exhibition.Name;
                        form["Alias"] = exhibition.Alias;
                        form["StartDate"] = exhibition.StartDate.ToString("dd/MM/yyyy");
                        form["EndDate"] = exhibition.EndDate.ToString("dd/MM/yyyy");
                        form["Description"] = exhibition.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 exhibition name</li>");
                        }
                        if (form["Alias"].Trim() == "")
                        {
                            stringBuilder.Append("<li>Please type exhibition alias</li>");
                        }
                        else
                        {
                            if (form["Alias"].Trim() != exhibition.Alias)
                            {
                                try
                                {
                                    string alias = form["Alias"].Trim().ToString();
                                    var exhibitions = db.Exhibitions.Where(c => c.Alias == alias).First();
                                    stringBuilder.Append("<li>This competition alias had been exists in database, try a different</li>");
                                }
                                catch { }
                            }
                        }
                        if (form["Description"].Trim() == "")
                        {
                            stringBuilder.Append("<li>Please type exhibition description</li>");
                        }
                        DateTime StartDate = new DateTime();
                        DateTime EndDate = new DateTime();
                        try
                        {
                            StartDate = DateTime.Parse(form["StartDate"]);
                        }
                        catch
                        {
                            stringBuilder.Append("<li>Please type exhibition start date</li>");
                        }
                        try
                        {
                            EndDate = DateTime.Parse(form["EndDate"]);
                        }
                        catch
                        {
                            stringBuilder.Append("<li>Please type exhibition deadline date</li>");
                        }
                        try
                        {
                            if (DateTime.Parse(form["EndDate"]) <= DateTime.Parse(form["StartDate"]))
                            {
                                stringBuilder.Append("<li>End date should after start date</li>");
                            }
                        }
                        catch
                        {

                        }

                        if (stringBuilder.ToString() == "<ul>")
                        {
                            if (Images != null)
                            {
                                string fileOldName = Server.MapPath("~/Content/Images/exhibitions/" + exhibition.Alias + ".jpg");
                                FilesClass.DeleteFile(fileOldName);
                                ImagesClass objImageClass = new ImagesClass(Images);
                                string fileSaveName = Server.MapPath("~/Content/Images/exhibitions/" + form["Alias"] + ".jpg");
                                objImageClass.CreateNewImage(fileSaveName, 190, 190);
                            }
                            else
                            {
                                if (form["Alias"].Trim() != exhibition.Alias)
                                {
                                    string fileOldName = Server.MapPath("~/Content/Images/exhibitions/" + exhibition.Alias + ".jpg");
                                    string fileNewName = Server.MapPath("~/Content/Images/exhibitions/" + form["Alias"] + ".jpg");
                                    FilesClass.RenameFile(fileOldName, fileNewName);
                                }
                            }
                            Exhibitions exhibitionsModels;
                            exhibitionsModels = db.Exhibitions.Where(c => c.ID == idd).First();
                            exhibitionsModels.Name = form["Name"];
                            exhibitionsModels.Alias = form["Alias"];
                            exhibitionsModels.Image = form["Alias"] + ".jpg";
                            exhibitionsModels.StartDate = StartDate;
                            exhibitionsModels.EndDate = EndDate;
                            exhibitionsModels.Description = form["Description"].Trim();
                            ViewBag.dataForm = form;
                            ViewBag.success = "Update exhibition 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");
            }
        }
コード例 #5
0
        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();
                if (form["submit_exhibition"] != null)
                {
                    StringBuilder stringBuilder = new StringBuilder();
                    stringBuilder.Append("<ul>");
                    Strings stringsLibs = new Strings();
                    if (form["Name"].Trim() == "")
                    {
                        stringBuilder.Append("<li>Please type exhibition name</li>");
                    }
                    if (form["Alias"].Trim() == "" || !Validator.ISAlias(form["Alias"]))
                    {
                        stringBuilder.Append("<li>Please type exhibition alias</li>");
                    }
                    else
                    {
                        try
                        {
                            string alias = form["Alias"].Trim().ToString();
                            var exhibition = db.Exhibitions.Where(c => c.Alias == alias).First();
                            stringBuilder.Append("<li>This exhibition alias had been exists in database, try a different</li>");
                        }
                        catch { }
                    }
                    if (form["Description"].Trim() == "")
                    {
                        stringBuilder.Append("<li>Please type exhibition description</li>");
                    }
                    DateTime StartDate = new DateTime();
                    DateTime EndDate = new DateTime();
                    try
                    {
                        StartDate = DateTime.Parse(form["StartDate"]);
                    }
                    catch
                    {
                        stringBuilder.Append("<li>Please type exhibition start date</li>");
                    }
                    try
                    {
                        EndDate = DateTime.Parse(form["EndDate"]);
                    }
                    catch
                    {
                        stringBuilder.Append("<li>Please type exhibition deadline date</li>");
                    }
                    try
                    {
                        if (DateTime.Parse(form["EndDate"]) <= DateTime.Parse(form["StartDate"]))
                        {
                            stringBuilder.Append("<li>End date should after start date</li>");
                        }
                    }
                    catch
                    {

                    }
                    if (Images == null)
                    {
                        stringBuilder.Append("<li>Please chose a image for this exhibition</li>");
                    }
                    if (stringBuilder.ToString() == "<ul>")
                    {
                        ImagesClass objImageClass = new ImagesClass(Images);
                        string fileSaveName = Server.MapPath("~/Content/Images/exhibitions/" + form["Alias"] + ".jpg");
                        objImageClass.CreateNewImage(fileSaveName, 190, 190);
                        Exhibitions exhibitionsModels = new Exhibitions
                        {
                            Name = form["Name"].Trim(),
                            Alias = form["Alias"].Trim(),
                            Image = form["Alias"].Trim() + ".jpg",
                            StartDate = StartDate,
                            EndDate = EndDate,
                            Description = form["Description"].Trim()
                        };
                        db.Exhibitions.Add(exhibitionsModels);
                        db.SaveChanges();
                        ViewBag.success = "Add exhibition success!";
                    }
                    else
                    {
                        stringBuilder.Append("</ul>");
                        ViewBag.error = stringBuilder.ToString();
                        ViewBag.dataForm = form;
                    }
                }
                return View();
            }
            else
            {
                Session["errorContorllerAction"] = true;
                return Redirect("~/administrator");
            }
        }
コード例 #6
0
        public ActionResult Edit(string id, FormCollection form, HttpPostedFileBase Icon)
        {
            int admin = base.Authentication();
            if (admin == 0)
            {
                return Redirect("~/member/logout");
            }
            else if (admin == 1)
            {
                base.LoadMenu();
                try
                {
                    var db = new FineArtContext();
                    var query = db.Menus.Where(m => m.ParentID == -1);
                    int idd = Convert.ToInt16(id);
                    var menu = db.Menus.Where(m => m.ID == idd).FirstOrDefault();
                    if (form["submit_menu"] == null)
                    {
                        form["Name"] = menu.Name;
                        form["Controller"] = menu.Controller;
                        form["Action"] = menu.Action;
                        if (menu.Display)
                        {
                            form["Display"] = "on";
                        }
                        form["Parent"] = menu.ParentID.ToString();
                        form["Description"] = menu.Description;
                    }
                    else
                    {
                        StringBuilder stringBuilder = new StringBuilder();
                        stringBuilder.Append("<ul>");
                        Strings stringsLibs = new Strings();
                        if (form["Name"].Trim() == "")
                        {
                            stringBuilder.Append("<li>Please type menu name</li>");
                        }
                        else
                        {
                            if (form["Name"].Trim() != menu.Name)
                            {
                                try
                                {
                                    string name = form["Name"];
                                    menu = db.Menus.Where(m => m.Name == name).First();
                                    stringBuilder.Append("<li>This menu had been exists in database. Try a different.</li>");
                                }
                                catch
                                {

                                }
                            }
                        }
                        int Parent = Convert.ToInt16(form["Parent"]);
                        bool Display = false;
                        if (Parent != -1)
                        {
                            try
                            {
                                menu = db.Menus.Where(m => m.ID == Parent && m.ParentID == -1).First();
                                if (form["Display"] == "on")
                                {
                                    Display = true;
                                }
                            }
                            catch
                            {
                                stringBuilder.Append("<li>Please chose parent menu for this menu</li>");
                            }
                        }
                        else
                        {
                            Display = true;
                        }
                        if (stringBuilder.ToString() == "<ul>")
                        {
                            if (Icon != null)
                            {
                                ImagesClass imageClass = new ImagesClass(Icon);
                                string path = Server.MapPath("~/Content/Images/admins/menu-icon" + form["Alias"] + ".jpg");
                                imageClass.CreateNewImage(path, 18, 16);
                            }
                            menu = db.Menus.Where(m => m.ID == idd).First();
                            menu.Name = form["Name"].Trim();
                            menu.Controller = form["Controller"].Trim();
                            menu.Action = form["Action"].Trim();
                            menu.Description = form["Description"].Trim();
                            menu.Display = Display;
                            menu.Icon = form["Alias"].Trim() + ".jpg";
                            menu.ParentID = Parent;
                            db.SaveChanges();
                            ViewBag.success = "Update menu success!";
                            base.LoadMenu();
                        }
                        else
                        {
                            stringBuilder.Append("</ul>");
                            ViewBag.error = stringBuilder.ToString();
                            ViewBag.dataForm = form;
                        }
                    }
                    ViewBag.dataForm = form;
                    ViewBag.parentMenu = query;
                    return View();
                }
                catch
                {
                    return Redirect("~/");
                }
            }
            else
            {
                Session["errorContorllerAction"] = true;
                return Redirect("~/administrator");
            }
        }
コード例 #7
0
        public ActionResult Register(FormCollection form, HttpPostedFileBase Images)
        {
            if (Session["user-loged"] == null)
            {
                if (form["submit-register"] != null)
                {
                    var db = new FineArtContext();
                    StringBuilder stringBuilder = new StringBuilder();
                    stringBuilder.Append("<ul>");
                    if (form["name"].Trim() == "" || form["name"].Trim().ToLower() == "full name")
                    {
                        stringBuilder.Append("<li>Please type your full name.</li>");
                    }
                    if (form["username"].Trim() == "" || form["username"].Trim().ToLower() == "username")
                    {
                        stringBuilder.Append("<li>Please type username.</li>");
                    }
                    else
                    {
                        string username = form["username"].Trim();
                        Members member = db.Members.Where(m => m.Username == username).FirstOrDefault();
                        if (member != null)
                        {
                            stringBuilder.Append("<li>Has been exists this username in database. Try other username.</li>");
                        }
                    }
                    if (!Validator.ISEmail(form["email"]))
                    {
                        stringBuilder.Append("<li>Email not valid.</li>");
                    }
                    else if (form["email"] != form["verifyemail"])
                    {
                        stringBuilder.Append("<li>Please verify email.</li>");
                    }
                    else
                    {
                        string email = form["email"].Trim();
                        Members member = db.Members.Where(m => m.Email == email).FirstOrDefault();
                        if (member != null)
                        {
                            stringBuilder.Append("<li>This email has been using. Try other email.</li>");
                        }
                    }

                    if (form["password"].Trim() == "" || form["password"].Trim().ToLower() == "password")
                    {
                        stringBuilder.Append("<li>Please type password.</li>");
                    }
                    else if (form["password"] != form["verifypassword"])
                    {
                        stringBuilder.Append("<li>Please verify password.</li>");
                    }
                    string birthday = form["day"] + "/" + form["month"] + "/" + form["year"];
                    DateTime Birthday = new DateTime();
                    try
                    {
                        Birthday = DateTime.Parse(birthday);
                    }
                    catch
                    {
                        stringBuilder.Append("<li>Your birthday not valid.</li>");
                    }

                    if (form["address"].Trim() == "" || form["address"].Trim().ToLower() == "address")
                    {
                        stringBuilder.Append("<li>Please type your address.</li>");
                    }

                    if (form["phone"].Trim() == "" || form["phone"].Trim().ToLower() == "phone")
                    {
                        stringBuilder.Append("<li>Please type your phone.</li>");
                    }
                    else if (!Validator.ISPhoneNumber(form["phone"]))
                    {
                        stringBuilder.Append("<li>Your phone number not valid.</li>");
                    }

                    if (Images == null)
                    {
                        stringBuilder.Append("<li>Please choose your avatar.</li>");
                    }
                    string gender;
                    switch (form["gender"])
                    {
                        case "0": gender = "Male"; break;
                        case "1": gender = "Female"; break;
                        default: gender = "Male"; break;
                    }

                    if (stringBuilder.ToString() == "<ul>")
                    {
                        MD5 md5Hash = MD5.Create();
                        Strings stringLib = new Strings();
                        string password = stringLib.GetMd5Hash(md5Hash, stringLib.GetMd5Hash(md5Hash, form["password"]) + "hashpassword");
                        eProjectsSemIII.Models.Roles role = db.Roles.Where(r => r.ID == 4).First();
                        ImagesClass imageLib = new ImagesClass(Images);
                        string path = Server.MapPath("~/Content/Images/students/" + form["username"] + ".jpg");
                        imageLib.CreateNewImage(path, 200, 240);
                        Members member = new Members
                        {
                            Name = form["name"].Trim(),
                            Username = form["username"].Trim(),
                            Password = password,
                            Email = form["email"].Trim(),
                            Birthday = Birthday,
                            Address = form["address"].Trim(),
                            Phone = form["phone"].Trim(),
                            Gender = gender,
                            Datejoin = DateTime.Now,
                            Images = form["username"].Trim() + ".jpg",
                            Role = role,
                        };
                        db.Members.Add(member);
                        db.SaveChanges();
                        ViewBag.success = true;
                    }
                    else
                    {
                        ViewBag.dataForm = form;
                        stringBuilder.Append("</ul>");
                        ViewBag.error = stringBuilder.ToString();
                    }
                }
            }
            else
            {
                return Redirect("~/");
            }
            return View();
        }