Ejemplo n.º 1
0
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            _context3.Activities.Add(Activity);
            await _context3.SaveChangesAsync();

            return(RedirectToPage("/Index"));
        }
Ejemplo n.º 2
0
        public async Task <IHttpActionResult> PostNewEvent(EventView eventView)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            DateTime dateTime;

            try
            {
                char[]     delimiters = new char[] { '.', ':', ' ' };
                string[]   values     = eventView.DateAndTime.Split(delimiters, StringSplitOptions.RemoveEmptyEntries);
                List <int> numbers    = new List <int>();

                foreach (string value in values)
                {
                    numbers.Add(int.Parse(value));
                }

                dateTime = new DateTime(numbers[2], numbers[1], numbers[0], numbers[3], numbers[4], 0);
            }
            catch (Exception ex)
            {
                throw ex;
            }

            Event newEvent = new Event {
                EventName = eventView.EventName,
                DateTime  = dateTime,
                Duration  = eventView.Duration
            };

            db.Events.Add(newEvent);

            await db.SaveChangesAsync();

            return(Ok(newEvent));//CreatedAtRoute("DefaultApi", new { id = newEvent.Id }, newEvent);
        }