Exemplo n.º 1
0
        public ActionResult Create(MVCEventBench.Models.Event eventSave)
        {
            //// Validation on fields before passing the information to the database
            //// When the flag = true, the value is not valid.
            //bool bFlagTitle = false;
            //bool bFlagImage = false;
            //bool bFlagAddress = false;
            //bool bFlagState = false;
            //bool bFlagSponsor = false;
            //bool bFlagPhone = false;
            //bool bFlagLocation = false;
            //bool bFlagDate = false;
            //int intParseTest;
            //bool bParseTest;
            //int intCompareDateTime;
            //DateTime dParseTest;

            //bool bFlagInvalidData = false;
            //string strInvalidData = "Some of the data you entered is incorrect. Please correct these values and re-submit the form broski!";

            ////Event Title Validation - cannot be less than 4 characters
            //if (eventSave.strEventName.Length < 4)
            //    bFlagTitle = true;
            ////Image Validation - must have selected a file, but will wait on this for now.
            ////Address Validation - cannot be less than 4 characters
            //if (eventSave.strEventAddress.Length < 4)
            //    bFlagAddress = true;
            ////State Validation - cannot be less than 2 characters and cannot be a number
            ////Actually, we might just use comboboxes for these, but meh.
            //if (eventSave.strEventState.Length < 2 || int.TryParse(eventSave.strEventState.ToString(), out intParseTest))
            //    bFlagState = true;
            ////City Validation - probably going to have drop downs, so ignoring for now
            ////Sponsor Validation - cannot be less than 4 characters
            //if (eventSave.strSponsor.Length < 4)
            //    bFlagSponsor = true;
            ////Phone Validation - cannot include characters or be less than 7 digits
            //if (!int.TryParse(eventSave.strPhoneNumber.ToString(), out intParseTest) || eventSave.strPhoneNumber.Length < 7)
            //    bFlagPhone = true;
            ////Location Validation - cannot be less than 4 characters
            //if (eventSave.strEventLocation.Length < 4)
            //    bFlagLocation = true;
            ////Date Validation - must be a datetime valid input and also not earlier than current time
            ////Added try-catch because the comparison test requires a non-null DateTime.
            //try
            //{
            //    if (!DateTime.TryParse(eventSave.dEventDateStart.ToString(), out dParseTest))
            //        bFlagDate = true;
            //    intCompareDateTime = DateTime.Compare(DateTime.Today, (DateTime)eventSave.dEventDateStart);
            //    if (intCompareDateTime > 0)
            //        bFlagDate = true;
            //}
            //catch
            //{
            //    bFlagDate = true;
            //}

            //if(bFlagAddress || bFlagDate || bFlagImage || bFlagLocation || bFlagPhone || bFlagSponsor || bFlagState || bFlagTitle)
            //    bFlagInvalidData = true;
            //if(bFlagInvalidData)
            //{
            //    return View();
            //}

            MVCEventBench.Models.dbEventModel db = new MVCEventBench.Models.dbEventModel();

            try
            {
                //Create a guid for the event
                Guid gEvent = Guid.NewGuid();

                //Create the event
                eventSave.gEventGUID = gEvent;
                db.AddToEvent(eventSave);
                db.SaveChanges();

                //Upload the event image..There should only ever be but one
                foreach (string upload in Request.Files)
                {
                    //Add logic here to only accept certain MIME types?
                    string strMimeType      = Request.Files[upload].ContentType;
                    Stream streamFileStream = Request.Files[upload].InputStream;
                    string strFileName      = Path.GetFileName(Request.Files[upload].FileName);

                    int    fileLength = Request.Files[upload].ContentLength;
                    byte[] fileData   = new byte[fileLength];
                    streamFileStream.Read(fileData, 0, fileLength);
                    fileData = ResizeImage(fileData, fileLength);

                    MVCEventBench.Models.Image myImage = new MVCEventBench.Models.Image();
                    myImage.gEventImageGUID = Guid.NewGuid();
                    myImage.gEvent          = gEvent;
                    myImage.imgContent      = fileData;
                    myImage.strMIMEType     = strMimeType;
                    myImage.strFileName     = strFileName;

                    db.AddToImage(myImage);
                    db.SaveChanges();
                }

                return(RedirectToAction("/Home/Index"));
            }
            catch
            {
                return(View());
            }
        }
Exemplo n.º 2
0
        //Method to quickly create test events
        public void CreateTestEvents(List <NailVent> listNailVentToday, List <NailVent> listNailVentWeek, List <NailVent> listNailVentMonth, string strState)
        {
            //First clear all events in the database
            MVCEventBench.Models.dbEventModel db = new MVCEventBench.Models.dbEventModel();
            var qry = from r in db.Event
                      select r;

            foreach (MVCEventBench.Models.Event evnt in qry)
            {
                var qry2 = from r2 in db.Image
                           where r2.gEvent == evnt.gEventGUID
                           select r2;

                foreach (MVCEventBench.Models.Image imgs in qry2)
                {
                    db.Image.DeleteObject(imgs);
                }

                db.Event.DeleteObject(evnt);
            }

            db.SaveChanges();


            //Create a List of test cities and countries
            List <string> listCities = new List <string>();

            listCities.Add("Clarksville");
            listCities.Add("Clarksville");
            listCities.Add("Martin");
            listCities.Add("Martin");
            listCities.Add("Dover");
            listCities.Add("Dover");
            listCities.Add("Nasville");
            listCities.Add("Nashville");
            listCities.Add("Dickson");
            listCities.Add("Dickson");

            int count = 0;

            //Day column test events
            while (count < 10)
            {
                //create day events
                try
                {
                    //create an empty event
                    MVCEventBench.Models.Event myTestEvent = new Models.Event();

                    //Create a guid for the event
                    Guid gEvent = Guid.NewGuid();

                    //Create the event
                    myTestEvent.gEventGUID           = gEvent;
                    myTestEvent.bIsDeleted           = false;
                    myTestEvent.dEventDateStart      = DateTime.Now.Date;
                    myTestEvent.dEventDateEnd        = DateTime.Now.Date;
                    myTestEvent.strAddressFontFamily = "Lucida";
                    myTestEvent.strAddressFontSize   = "12";
                    myTestEvent.strContact           = "Test Contact";
                    myTestEvent.strDateFontFamily    = "Lucida";
                    myTestEvent.strDateFontSize      = "12";
                    myTestEvent.strDescription       = "Test Description";
                    myTestEvent.strDetails           = "Test Details";
                    myTestEvent.strEventAddress      = "Test Address";
                    myTestEvent.strEventCity         = listCities[count];
                    myTestEvent.strEventLocation     = "Test Location";
                    myTestEvent.strEventName         = "Test Day";
                    myTestEvent.strEventState        = strState;
                    myTestEvent.strPhoneNumber       = "931-216-0359";
                    myTestEvent.strSponsor           = "Test sponsor";
                    myTestEvent.strTag1            = "Music";
                    myTestEvent.strTag2            = "Gaming";
                    myTestEvent.strTag3            = "Sports";
                    myTestEvent.strTitleFontFamily = "Lucida";
                    myTestEvent.strWebpage         = "www.TestWebpage.com";

                    db.AddToEvent(myTestEvent);
                    db.SaveChanges();

                    //Upload the event image..There should only ever be but one

                    MVCEventBench.Models.Image myImage = new MVCEventBench.Models.Image();
                    myImage.gEventImageGUID = Guid.NewGuid();
                    myImage.gEvent          = gEvent;

                    Image        ImageTest = Image.FromFile(@"C:\Documents and Settings\Owner\My Documents\Visual Studio 2010\Projects\Event\Event\bin\MVCEventBench.root\MVCEventBench\MVCEventBench\Content\Winter.jpg");
                    MemoryStream ms        = new MemoryStream();
                    ImageTest.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);


                    myImage.strAltImageName = "test";
                    myImage.bIsDeleted      = false;
                    myImage.imgContent      = ms.ToArray();
                    myImage.strMIMEType     = "image/jpeg";
                    myImage.strFileName     = "stripe.jpg";

                    db.AddToImage(myImage);
                    db.SaveChanges();

                    count++;
                }
                catch { };
            }

            //Week column test events
            count = 0;
            while (count < 10)
            {
                //create day events
                try
                {
                    //create an empty event
                    MVCEventBench.Models.Event myTestEvent = new Models.Event();

                    //Create a guid for the event
                    Guid gEvent = Guid.NewGuid();

                    //Create the event
                    myTestEvent.gEventGUID           = gEvent;
                    myTestEvent.bIsDeleted           = false;
                    myTestEvent.dEventDateStart      = DateTime.Now.Date.AddDays(2.0);
                    myTestEvent.dEventDateEnd        = DateTime.Now.Date;
                    myTestEvent.strAddressFontFamily = "Lucida";
                    myTestEvent.strAddressFontSize   = "12";
                    myTestEvent.strContact           = "Test Contact";
                    myTestEvent.strDateFontFamily    = "Lucida";
                    myTestEvent.strDateFontSize      = "12";
                    myTestEvent.strDescription       = "Test Description";
                    myTestEvent.strDetails           = "Test Details";
                    myTestEvent.strEventAddress      = "Test Address";
                    myTestEvent.strEventCity         = listCities[count];
                    myTestEvent.strEventLocation     = "Test Location";
                    myTestEvent.strEventName         = "Test Week";
                    myTestEvent.strEventState        = strState;
                    myTestEvent.strPhoneNumber       = "931-216-0359";
                    myTestEvent.strSponsor           = "Test sponsor";
                    myTestEvent.strTag1            = "Music";
                    myTestEvent.strTag2            = "Gaming";
                    myTestEvent.strTag3            = "Sports";
                    myTestEvent.strTitleFontFamily = "Lucida";
                    myTestEvent.strWebpage         = "www.TestWebpage.com";

                    db.AddToEvent(myTestEvent);
                    db.SaveChanges();

                    //Upload the event image..There should only ever be but one

                    MVCEventBench.Models.Image myImage = new MVCEventBench.Models.Image();
                    myImage.gEventImageGUID = Guid.NewGuid();
                    myImage.gEvent          = gEvent;

                    Image        ImageTest = Image.FromFile(@"C:\Documents and Settings\Owner\My Documents\Visual Studio 2010\Projects\Event\Event\bin\MVCEventBench.root\MVCEventBench\MVCEventBench\Content\Winter.jpg");
                    MemoryStream ms        = new MemoryStream();
                    ImageTest.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);


                    myImage.strAltImageName = "test";
                    myImage.bIsDeleted      = false;
                    myImage.imgContent      = ms.ToArray();
                    myImage.strMIMEType     = "image/jpeg";
                    myImage.strFileName     = "stripe.jpg";

                    db.AddToImage(myImage);
                    db.SaveChanges();

                    count++;
                }
                catch { };
            }

            //Month column test events
            count = 0;
            while (count < 10)
            {
                //create day events
                try
                {
                    //create an empty event
                    MVCEventBench.Models.Event myTestEvent = new Models.Event();

                    //Create a guid for the event
                    Guid gEvent = Guid.NewGuid();

                    //Create the event
                    myTestEvent.gEventGUID           = gEvent;
                    myTestEvent.bIsDeleted           = false;
                    myTestEvent.dEventDateStart      = DateTime.Now.Date.AddDays(12.0);
                    myTestEvent.dEventDateEnd        = DateTime.Now.Date;
                    myTestEvent.strAddressFontFamily = "Lucida";
                    myTestEvent.strAddressFontSize   = "12";
                    myTestEvent.strContact           = "Test Contact";
                    myTestEvent.strDateFontFamily    = "Lucida";
                    myTestEvent.strDateFontSize      = "12";
                    myTestEvent.strDescription       = "Test Description";
                    myTestEvent.strDetails           = "Test Details";
                    myTestEvent.strEventAddress      = "Test Address";
                    myTestEvent.strEventCity         = listCities[count];
                    myTestEvent.strEventLocation     = "Test Location";
                    myTestEvent.strEventName         = "Test Month";
                    myTestEvent.strEventState        = strState;
                    myTestEvent.strPhoneNumber       = "931-216-0359";
                    myTestEvent.strSponsor           = "Test sponsor";
                    myTestEvent.strTag1            = "Music";
                    myTestEvent.strTag2            = "Gaming";
                    myTestEvent.strTag3            = "Sports";
                    myTestEvent.strTitleFontFamily = "Lucida";
                    myTestEvent.strWebpage         = "www.TestWebpage.com";

                    db.AddToEvent(myTestEvent);
                    db.SaveChanges();

                    //Upload the event image..There should only ever be but one

                    MVCEventBench.Models.Image myImage = new MVCEventBench.Models.Image();
                    myImage.gEventImageGUID = Guid.NewGuid();
                    myImage.gEvent          = gEvent;

                    Image        ImageTest = Image.FromFile(@"C:\Documents and Settings\Owner\My Documents\Visual Studio 2010\Projects\Event\Event\bin\MVCEventBench.root\MVCEventBench\MVCEventBench\Content\Winter.jpg");
                    MemoryStream ms        = new MemoryStream();
                    ImageTest.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);

                    myImage.strAltImageName = "test";
                    myImage.bIsDeleted      = false;
                    myImage.imgContent      = ms.ToArray();
                    myImage.strMIMEType     = "image/jpeg";
                    myImage.strFileName     = "stripe.jpg";

                    db.AddToImage(myImage);
                    db.SaveChanges();

                    count++;
                }
                catch { };
            }
        }