Exemplo n.º 1
0
        public async Task <IActionResult> Create(EventPostViewModel eventPostModel)
        {
            if (ModelState.IsValid)
            {
                var eventForSave = _mapper.Map <EventPostViewModel, Event>(eventPostModel);

                var eventFromDb = _eventData.AddEvent(eventForSave);

                var fileExt = eventPostModel.Wallpaper.FileName.Split('.').Last();

                string path = $"{Path.DirectorySeparatorChar}images{Path.DirectorySeparatorChar}" +
                              $"eventWallpapers{Path.DirectorySeparatorChar}"
                              + eventFromDb.Id + $".{fileExt}";


                using (var fileStream = new FileStream(_env.WebRootPath + path, FileMode.Create))
                {
                    await eventPostModel.Wallpaper.CopyToAsync(fileStream);
                }

                eventFromDb.ImageUrl  = "/images/eventWallpapers/" + eventFromDb.Id + $".{fileExt}";
                eventFromDb.Organizer = await _userManager.GetUserAsync(User);

                eventFromDb.ImageLocalUrl = _env.WebRootPath + path;
                _eventData.UpdateEvent(eventFromDb);
                return(RedirectToAction("Index", "Profile"));
            }
            return(View());
        }
Exemplo n.º 2
0
        private EventRow ParseEventEnd(EventRow @event, IEventData data)
        {
            if (@event == null)
            {
                this.error.AppendLine("No event");
                return(@event);
            }

            if (string.IsNullOrEmpty(@event.Id))
            {
                this.error.AppendLine("Invalid event id");
                return(@event);
            }

            var start = $"[{@event.Id}]";
            var end   = this.Event;

            if (!start.Equals(end))
            {
                this.error.AppendLine("Mismatched event start and end tokens");
                return(@event);
            }

            data.AddEvent(@event);
            return(null);
        }