Ejemplo n.º 1
0
        public override void OnActionExecuted(ActionExecutedContext context)
        {
            ///Console and file Logger used, the log for me is in the .Web project root directory.
            ///Everything is logged, not only the custom message here.
            ///The log gets lost in other logs search for "Administrator"

            if (!context.ModelState.IsValid)
            {
                logger.LogInformation($"Event \"{context.HttpContext.Request.Form["Name"]}\" was not created because of invalid data!");
                return;
            }

            var eventCreateModel = new EventCreateBindingModel
            {
                End            = DateTime.ParseExact(context.HttpContext.Request.Form["EndString"], "dd/MM/yyyy HH:mm", CultureInfo.InvariantCulture),
                Start          = DateTime.ParseExact(context.HttpContext.Request.Form["StartString"], "dd/MM/yyyy HH:mm", CultureInfo.InvariantCulture),
                Name           = context.HttpContext.Request.Form["Name"],
                Place          = context.HttpContext.Request.Form["Place"],
                PricePerTicket = decimal.Parse(context.HttpContext.Request.Form["PricePerTicket"]),
                TotalTickets   = int.Parse(context.HttpContext.Request.Form["TotalTickets"])
            };

            //if (!context.ModelState.IsValid)
            //{
            //    logger.LogInformation($"Event \"{eventCreateModel.Name}\" was not created because of invalid data!");
            //    return;
            //}

            logger.LogInformation($"[{DateTime.UtcNow.ToEventuresFormat()}] " +
                                  $"Administrator {context.HttpContext.User.Identity.Name} create " +
                                  $"event {eventCreateModel.Name} ({eventCreateModel.Start.ToEventuresFormat()} /" +
                                  $" {eventCreateModel.End.ToEventuresFormat()}).");
            base.OnActionExecuted(context);
        }
Ejemplo n.º 2
0
        public IActionResult Create(EventCreateBindingModel model)
        {
            if (ModelState.IsValid)
            {
                eventsService.Create(model);
                return(Redirect("/"));
            }

            return(View(model));
        }
Ejemplo n.º 3
0
        public async Task <IActionResult> Create(EventCreateBindingModel model)
        {
            var serviceModel = Mapper.Map <EventServiceModel>(model);

            await this.eventService.CreateAsync(serviceModel);

            this.logger.LogInformation("Event created: " + serviceModel.Name, serviceModel);

            return(this.RedirectToAction("All"));
        }
Ejemplo n.º 4
0
        public void Create(EventCreateBindingModel model)
        {
            var eventInstance = new Event
            {
                End            = DateTime.ParseExact(model.EndString, "dd/MM/yyyy HH:mm", CultureInfo.InvariantCulture),
                Start          = DateTime.ParseExact(model.StartString, "dd/MM/yyyy HH:mm", CultureInfo.InvariantCulture),
                Name           = model.Name,
                Place          = model.Place,
                PricePerTicket = model.PricePerTicket,
                TotalTickets   = model.TotalTickets,
            };

            context.Events.Add(eventInstance);
            context.SaveChanges();
        }
        //[AdminCreateLoggerFilter]
        public async Task <IActionResult> Create(EventCreateBindingModel model)
        {
            if (ModelState.IsValid)
            {
                var @event = new Event
                {
                    Name           = model.Name,
                    Place          = model.Place,
                    Start          = model.Start,
                    End            = model.End,
                    TotalTickets   = model.TotalTickets,
                    PricePerTicket = model.PricePerTicket,
                };
                _context.Add(@event);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(All)));
            }
            return(View(model));
        }
Ejemplo n.º 6
0
        public IActionResult Create(EventCreateBindingModel bindingModel)
        {
            if (this.ModelState.IsValid)
            {
                Event eventForDb = new Event()
                {
                    Name           = bindingModel.Name,
                    End            = bindingModel.End,
                    Start          = bindingModel.Start,
                    Place          = bindingModel.Place,
                    PricePerTicket = bindingModel.PricePerTicket,
                    TotalTckets    = bindingModel.TotalTickets
                };
                _context.Events.Add(eventForDb);
                _context.SaveChanges();

                return(this.Redirect("All"));
            }
            return(this.View());
        }
        public IActionResult Create(EventCreateBindingModel bindingModel)
        {
            if (this.ModelState.IsValid)
            {
                Event eventForDb = new Event
                {
                    Id             = Guid.NewGuid().ToString(),
                    Name           = bindingModel.Name,
                    End            = bindingModel.End,
                    Place          = bindingModel.Place,
                    Start          = bindingModel.Start,
                    PricePerTicket = bindingModel.PricePerTicket,
                    TotalTickets   = bindingModel.TotalTickets
                };

                this.context.Events.Add(eventForDb);
                this.context.SaveChanges();

                return(RedirectToAction("All"));
            }
            return(this.View());
        }
Ejemplo n.º 8
0
        public IActionResult Create(EventCreateBindingModel model)
        {
            if (this.ModelState.IsValid)
            {
                Event eventForDb = new Event
                {
                    Name           = model.Name,
                    Place          = model.Place,
                    Start          = model.Start,
                    End            = model.End,
                    TotalTickets   = model.TotalTickets,
                    PricePerTicket = model.PricePerTicket
                };

                context.Events.Add(eventForDb);
                context.SaveChanges();

                return(this.RedirectToAction("All"));
            }

            return(this.View());
        }