예제 #1
0
        public ActionResult Delete([Bind(Include = "Id,Title,Description,StartAt,EndAt,IsFullDay")] Eventful workoutEvent)
        {
            if (ModelState.IsValid)
            {
                var    dayOfWeek = getDay(workoutEvent);
                string muscle    = getMuscleName(workoutEvent);

                using (var ctx = new ApplicationDbContext())
                {
                    var eventToDelete = from a in ctx.Eventfuls
                                        where a.Title == muscle
                                        select a;
                    foreach (var item in eventToDelete.ToList())
                    {
                        if (item.StartAt.DayOfWeek == dayOfWeek)
                        {
                            ctx.Eventfuls.Remove(item);
                            ctx.SaveChanges();
                        }
                    }
                }
            }

            return(RedirectToAction("Index"));
        }
예제 #2
0
        public static Task UpdateEventsFromEventful(Eventful eventfulEvent)
        {
            DataModel    db     = new DataModel();
            List <Event> events = db.Events.ToList();

            foreach (var eventfulEventEvent in eventfulEvent.Events.Event)
            {
                Event existingEvent = events.FirstOrDefault(x => x.EventfulUniqueId == eventfulEventEvent.Id);
                if (existingEvent == null)
                {
                    Event eventModel = new Event();

                    eventModel.Latitude         = eventfulEventEvent.Latitude;
                    eventModel.Longitude        = eventfulEventEvent.Longitude;
                    eventModel.Address          = eventfulEventEvent.VenueAddress;
                    eventModel.URL              = eventfulEventEvent.Url;
                    eventModel.EventfulUniqueId = eventfulEventEvent.Id;
                    eventModel.Name             = eventfulEventEvent.Title;
                    eventModel.EventDate        = DateTime.ParseExact(eventfulEventEvent.StartTime, "yyyy-MM-dd HH:mm:ss", CultureInfo.InvariantCulture);
                    eventModel.Description      = String.IsNullOrEmpty(eventfulEventEvent.Description)
                        ? NoDescriptionAvailiable
                        : eventfulEventEvent.Description;
                    addQuadrantToEvent(eventModel);
                    db.Events.Add(eventModel);
                }
            }
            db.SaveChanges();

            return(Task.FromResult(0));
        }
예제 #3
0
        public ActionResult Create([Bind(Include = "Id,Title,Description,StartAt,EndAt,IsFullDay")] Eventful workoutEvent)
        {
            if (ModelState.IsValid)
            {
                var    dayOfWeek = getDay(workoutEvent);
                string muscle    = getMuscleName(workoutEvent);

                for (int i = DateTime.Now.Month; i < 12; i++)
                {
                    DateTime mondayz = new DateTime(2017, i, 1);
                    while (mondayz.Day <= DateTime.DaysInMonth(2017, i))
                    {
                        while (mondayz.DayOfWeek != dayOfWeek && mondayz.Day < DateTime.DaysInMonth(2017, i))
                        {
                            mondayz = mondayz.AddDays(1);
                        }
                        if (mondayz.DayOfWeek == dayOfWeek && mondayz.Day <= DateTime.DaysInMonth(2017, i))
                        {
                            using (var ct = new ApplicationDbContext())
                            {
                                var duplicateTest = from b in ct.Eventfuls
                                                    where b.Title == muscle && b.StartAt == mondayz.Date && b.userEmail == User.Identity.Name
                                                    select b;
                                int counter = duplicateTest.ToList().Count;
                                if (counter == 0)
                                {
                                    Eventful eventful3 = new Eventful
                                    {
                                        Title       = muscle,
                                        Description = "",
                                        StartAt     = mondayz.Date,
                                        EndAt       = mondayz.Date,
                                        IsFullDay   = workoutEvent.IsFullDay,
                                        userEmail   = User.Identity.Name
                                    };
                                    ct.Eventfuls.Add(eventful3);
                                    ct.SaveChanges();
                                }
                            }


                            if (mondayz.Day < DateTime.DaysInMonth(2017, i))
                            {
                                mondayz = mondayz.AddDays(1);
                            }
                        }
                        if (mondayz.Day == DateTime.DaysInMonth(2017, i))
                        {
                            break;
                        }
                    }
                }
                return(RedirectToAction("Index", "Calendar"));
            }

            return(View());
        }
예제 #4
0
 public ActionResult Edit([Bind(Include = "Id,Title,Description,StartAt,EndAt,IsFullDay")] Eventful eventful)
 {
     if (ModelState.IsValid)
     {
         db.Entry(eventful).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(eventful));
 }
예제 #5
0
        public string getMuscleName(Eventful workoutEvent)
        {
            using (var cta = new ApplicationDbContext())
            {
                var muscleName = from a in cta.Muscles
                                 where a.muscleId.ToString() == workoutEvent.Title
                                 select a.muscleName;

                var    fea    = muscleName.ToList();
                string muscle = fea[0];
                return(muscle);
            }
        }
예제 #6
0
        // GET: Eventfuls/Details/5
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Eventful eventful = db.Eventfuls.Find(id);

            if (eventful == null)
            {
                return(HttpNotFound());
            }
            return(View(eventful));
        }
예제 #7
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        private Object GetSource(String query, String data)
        {
            try
            {
                if (String.IsNullOrEmpty(query))
                {
                    return(null);
                }

                Eventful eventful = new Eventful();
                return(eventful.SearchEvents(query, 0, 6));
            }
            catch { }

            return(null);
        }
예제 #8
0
        public static async Task GetEventfulEvents()
        {
            HttpClient client = GetNewClient();
            string     url    = @"http://api.eventful.com/json/events/search?location=Calgary&app_key=H3hfv9tXr8PRXLTf";

            client.BaseAddress = new Uri(url);

            //add an accept header over here JSON format
            //comes back as text/javascript
            client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));

            HttpResponseMessage response = client.GetAsync("").Result;

            var eventfulString = response.Content.ReadAsStringAsync().Result;

            Eventful eventful = Eventful.FromJson(eventfulString);

            await EventMapper.UpdateEventsFromEventful(eventful);
        }
        public ActionResult Create([Bind(Include = "plansMessageId,recipientCategoryId,recipientId,Location,introMessage,closingMessage,planDate")] PlansMessage plansMessage)
        {
            if (ModelState.IsValid)
            {
                Eventful eventz = new Eventful
                {
                    Title       = plansMessage.Location,
                    Description = $"{plansMessage.introMessage}" + $",{plansMessage.closingMessage}",
                    StartAt     = plansMessage.planDate,
                    EndAt       = plansMessage.planDate,
                    IsFullDay   = "false"
                };
                db.Events.Add(eventz);
                db.PlansMessages.Add(plansMessage);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.recipientId         = new SelectList(db.Recipients, "recipientId", "nickName", plansMessage.recipientId);
            ViewBag.recipientCategoryId = new SelectList(db.RecipientCategories, "recipientCategoryId", "categoryName", plansMessage.recipientCategoryId);
            return(View(plansMessage));
        }
예제 #10
0
        public System.DayOfWeek getDay(Eventful workoutEvent)
        {
            System.DayOfWeek dayOfWeek = DayOfWeek.Monday;
            switch (workoutEvent.Description)
            {
            case "1":
                dayOfWeek = DayOfWeek.Monday;
                break;

            case "2":
                dayOfWeek = DayOfWeek.Tuesday;
                break;

            case "3":
                dayOfWeek = DayOfWeek.Wednesday;
                break;

            case "4":
                dayOfWeek = DayOfWeek.Thursday;
                break;

            case "5":
                dayOfWeek = DayOfWeek.Friday;
                break;

            case "6":
                dayOfWeek = DayOfWeek.Saturday;
                break;

            case "7":
                dayOfWeek = DayOfWeek.Sunday;
                break;
            }

            return(dayOfWeek);
        }