Example #1
0
        public async Task <IActionResult> CreateEvent(EventViewModel vm)
        {
            ViewBag.states = new SelectList(GetStates());

            if (!ModelState.IsValid)
            {
                return(View(vm));
            }
            var newEvent = Mapper.Map <Event>(vm);

            var currentUser = this.User;

            newEvent.Manager = await _userManager.FindByNameAsync(currentUser.Identity.Name);

            if (_repository.AddEvent(newEvent))
            {
                if (_repository.SaveAll())
                {
                    return(RedirectToAction("Events"));
                }
                ModelState.AddModelError("", "There was an error while saving to database");
                return(View(vm));
            }
            ModelState.AddModelError("", "There was an error adding the event.");
            return(View(vm));
        }