Exemplo n.º 1
0
        public CreateConferenceResponse CreateConference(CreateConferenceRequest request, ClaimsPrincipal claim)
        {
            var response = new CreateConferenceResponse();
            var user     = context.Users.FirstOrDefault(n => n.UserName == claim.Identity.Name);

            if (user == null)
            {
                response.AddNoPermissionError("You are not allowed to create a conference.");
                return(response);
            }

            var project = context.Projects.FirstOrDefault(n => n.ProjectId == request.ProjectId);

            if (project == null)
            {
                response.AddInvalidDataError("The Project was not found.", nameof(request.ProjectId));
                return(response);
            }

            // Create the conference
            var conference = new Conference()
            {
                Name              = request.Name,
                FullName          = request.FullName,
                ConferenceShort   = request.ConferenceShort,
                ConferenceProject = project,
                CreationDate      = DateTime.UtcNow,
                CreationUser      = user,
                StartDate         = request.StartDate,
                EndDate           = request.EndDate
            };

            var easyId = Util.IdGenerator.AsPrimaryKey(request.ConferenceShort);

            if (context.Conferences.All(n => n.ConferenceId != easyId))
            {
                conference.ConferenceId = easyId;
            }

            //if (DateTime.TryParse(request.StartDate, out DateTime start))
            //    conference.StartDate = start;

            //if (DateTime.TryParse(request.EndDate, out DateTime end))
            //    conference.EndDate = end;

            context.Conferences.Add(conference);


            CreateDefaultConferenceAuths(conference);

            context.SaveChanges();

            response.ConferenceId = conference.ConferenceId;

            return(response);
        }
Exemplo n.º 2
0
 public Task <ApiResponse> CreateAsync(CreateConferenceRequest request)
 => _client.PostAsync(Path, request);