// [HttpPost, Route("/api/posts/blogCategoryCreate")]
        public IActionResult CreateEventGroup([DataSourceRequest] DataSourceRequest request, CalendarEventGroup model)
        {
            if (ModelState.IsValid)
            {
                var userContext = _userContextAccessor.GetContext();
                Ensure.NotNull(userContext, "User context is missing.");
                Ensure.NotNullOrEmpty(userContext.UserId, "Cannot resolve user information.");

                if (string.IsNullOrEmpty(model?.EventGroupId) && !string.IsNullOrEmpty(model?.Title))
                {
                    var eventGroup = new CalendarEventGroup
                    {
                        Title        = model.Title,
                        UserId       = userContext.UserId,
                        SiteId       = _siteContext.SiteId,
                        EventGroupId = KeyGen.NewGuid()
                    };

                    eventGroup = _calendarQueryService.CreateEventGroup(eventGroup);

                    return(Json(new[] { eventGroup }.ToDataSourceResult(request, ModelState)));
                }

                return(Ok(model));
            }

            return(BadRequest(ModelState));
        }
Exemple #2
0
        public CalendarEventGroup CreateEventGroup(CalendarEventGroup eventGroup)
        {
            var existingGroup = _calendarDbContext.CalendarEventGroups.FirstOrDefault(x => x.Title == eventGroup.Title && x.UserId == eventGroup.UserId);

            if (existingGroup == null)
            {
                _calendarDbContext.CalendarEventGroups.Add(eventGroup);
                _calendarDbContext.SaveChanges();
            }
            else
            {
                eventGroup = existingGroup;
            }
            return(eventGroup);
        }