Пример #1
0
        public async Task <bool> AddEvent(EventCreateVM model)
        {
            try
            {
                var conferenceEvent = new ConferenceEvent
                {
                    Id        = Guid.NewGuid(),
                    Name      = model.Name,
                    Date      = DateTime.Now,
                    Time      = model.Time,
                    Price     = model.Price,
                    ImageUrl  = model.ImageUrl,
                    OnlineUrl = model.OnlineUrl,
                    Location  = model.Location == null? null : new Location {
                        Address = model.Location.Address, City = model.Location.City, Country = model.Location.Country
                    }
                };
                await _eventService.AddEvent(conferenceEvent);

                return(true);
            }
            catch (RecordAlreadyExistException)
            {
                throw;
            }
            catch (Exception)
            {
                throw;
            }
        }
Пример #2
0
        public async Task <IActionResult> Create([FromBody] EventCreateVM model)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    var response = await _eventHandler.AddEvent(model);

                    return(Ok(new APIResponse {
                        ResponseObject = response
                    }));
                }
                else
                {
                    return(BadRequest(new APIResponse {
                        Error = true, ErrorMessage = "Bad request", ErrorCode = "001"
                    }));
                }
            }
            catch (RecordAlreadyExistException ex)
            {
                return(BadRequest(new APIResponse {
                    Error = true, ErrorMessage = "Bad request", ErrorCode = "001"
                }));
            }
            catch (Exception)
            {
                return(BadRequest(new APIResponse {
                    Error = true, ErrorMessage = "Exception", ErrorCode = "999"
                }));
            }
        }
Пример #3
0
        public async Task <IActionResult> CreatePost(EventCreateVM eventVM)
        {
            ViewBag.Speakers = _db.Speakers.ToList();
            if (!ModelState.IsValid)
            {
                return(View());
            }
            string keys = Request.Form["speakers"];

            if (keys == null)
            {
                ModelState.AddModelError(string.Empty, "Choose at Least one speaker");
                return(View());
            }
            string[]   _keys = keys.Split(',');
            List <int> ids   = new List <int>();

            foreach (var item in _keys)
            {
                ids.Add(Int32.Parse(item));
            }
            if (!eventVM.Photo.isImage())
            {
                ModelState.AddModelError(string.Empty, "Choose photo");
                return(View());
            }


            Event _event = new Event
            {
                Date       = eventVM.Date,
                Header     = eventVM.Header,
                Definition = eventVM.Definition,
                Interval   = eventVM.Interval,
                Location   = eventVM.Location,
                Content    = eventVM.Content,
                Image      = await eventVM.Photo.SaveImg(_env.WebRootPath, "img/event")
            };
            List <EventSpeaker> eSpeaker = new List <EventSpeaker>();

            foreach (int item in ids)
            {
                eSpeaker.Add(new EventSpeaker
                {
                    EventId   = _event.Id,
                    SpeakerId = item
                });
            }

            _event.EventSpeakers = eSpeaker;

            _db.Events.Add(_event);
            await _db.SaveChangesAsync();

            return(RedirectToAction(nameof(Index)));
        }
Пример #4
0
        public async Task <IActionResult> Create([Bind("Title,Date,Duration,TypeId")] EventCreateVM eventVm)
        {
            if (ModelState.IsValid)
            {
                var addEvent = new Event()
                {
                    Title    = eventVm.Title,
                    Date     = eventVm.Date,
                    Duration = eventVm.Duration,
                    TypeId   = eventVm.TypeId
                };

                _context.Add(addEvent);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(eventVm));
        }
Пример #5
0
        public ActionResult Create([Bind(Include = "Name,IsHistory,AboutText,NormalParticipants,DateMonth,DateSeason, Blurb, IsSecret")] EventCreateVM taevent,
                                   List <short> tags,
                                   string submit)
        {
            taevent.IsPublished = false;
            if (ModelState.IsValid)
            {
                #region Info
                Info info;
                info = new Info
                {
                    InfoTypeId   = 6, //<-------------------Info Type ID. CHANGE UPON COPY
                    IdWithinType = null,
                    Blurb        = taevent.Blurb,
                    Name         = taevent.Name,
                    IsPublished  = taevent.IsPublished,
                    IsSecret     = taevent.IsSecret
                };
                db.Infos.Add(info);
                db.SaveChanges(); //this has to go here in order to ensure that the infoId short below is accurate. Also at this point I am doing no further gets on validity so there is no point to not saving
                #endregion
                short infoId = db.Infos.Max(i => i.InfoId);

                #region Adding Tags
                if (tags != null)
                {
                    foreach (short t in tags)
                    {
                        InfoTag infoTag = new InfoTag {
                            InfoId = infoId, TagId = t
                        };
                        db.InfoTags.Add(infoTag);
                    }
                }
                #endregion

                #region Event
                Event daEvent = new Event
                {
                    InfoId             = infoId,
                    Name               = taevent.Name,
                    IsHistory          = taevent.IsHistory,
                    AboutText          = taevent.AboutText,
                    NormalParticipants = taevent.NormalParticipants,
                    IsPublished        = taevent.IsPublished,
                    DateMonth          = taevent.DateMonth,
                    DateSeason         = taevent.DateSeason
                };
                db.Events.Add(daEvent);
                db.SaveChanges();
                #endregion

                #region give info the IdWithinType
                short maxi = db.Events.Max(l => l.EventId);
                info.IdWithinType    = maxi;
                db.Entry(info).State = EntityState.Modified;
                db.SaveChanges();
                #endregion

                //move to step 2
                return(RedirectToAction("AssoCreate", new { id = maxi, submit = submit }));
            }

            //if model is not valid
            ViewBag.Tags = new MultiSelectList(db.Tags, "TagId", "TagName", tags);

            ModelState.AddModelError("", "Something has gone wrong. Look for red text to see where is went wrong");
            return(View(taevent));
        }