Example #1
0
        public Post(Models.Post model, Models.BaseContext context)
        {
            Id           = model.Id;
            Title        = model.Title;
            Text         = model.Text;
            CreatedAt    = model.CreatedAt;
            LastModified = model.LastModified;

            if (context != null)
            {
                var author = context
                             .Users
                             .Find(model.AuthorId);

                Author = new Views.User(author);

                var comments = context
                               .Comments
                               .ToList()
                               .Where(x => x.PostId == model.Id);

                Comments = new List <Comment>();
                foreach (Models.Comment comment in comments)
                {
                    Comments.Add(new Views.Comment(comment, context));
                }
            }
        }
Example #2
0
        public async Task <IActionResult> Post([FromBody] Views.User view)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var user = await _UserService.Create(view);

            return(CreatedAtAction("Post", user));
        }
Example #3
0
        public async Task <Views.User> Create(Views.User view)
        {
            try
            {
                var language = await _Context.Languages
                               .SingleAsync(lng => lng.Code == view.Language);

                var role = await _Context.Roles
                           .SingleAsync(rle => rle.Name == "Moderator");

                _Context.Groups.Add(new Models.Group
                {
                    Personal  = true,
                    CreatedAt = DateTime.UtcNow
                });

                _Context.Users.Add(new Models.User
                {
                    Activated  = false,
                    Email      = view.Email,
                    Password   = view.Password,
                    FirstName  = view.FirstName,
                    LastName   = view.LastName,
                    LanguageId = language.Id,
                    CreatedAt  = DateTime.UtcNow
                });

                var foo = _Context.Groups.Local.First();

                _Context.Memberships.Add(new Models.Membership
                {
                    GroupId   = _Context.Groups.Local.First().Id,
                    UserId    = _Context.Users.Local.First().Id,
                    RoleId    = role.Id,
                    CreatedAt = DateTime.UtcNow
                });

                await _Context.SaveChangesAsync();

                return(null);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Example #4
0
        public Post(Models.Post model)
        {
            Id           = model.Id;
            Title        = model.Title;
            Text         = model.Text;
            CreatedAt    = model.CreatedAt;
            LastModified = model.LastModified;

            if (model.Author != null)
            {
                Author = new Views.User(model.Author);
            }

            if (model.Comments != null)
            {
                Comments = new List <Comment>();
                foreach (var comment in model.Comments)
                {
                    Comments.Add(new Views.Comment(comment));
                }
            }
        }