Beispiel #1
0
        public IActionResult Post([FromBody] User.Data.User user)
        {
            if (!ModelState.IsValid)
            {
                var message = string.Join(" | ", ModelState.Values
                                          .SelectMany(v => v.Errors)
                                          .Select(e => e.ErrorMessage));
                return(BadRequest(message));
            }

            List <User.Data.User> oldUsers = this.userDataContext.Users.AsNoTracking().Where(old => old.DocumentTypeId == user.DocumentTypeId && old.DocumentId == user.DocumentId).ToList();

            if (oldUsers.Count() > 0)
            {
                foreach (var oldUser in oldUsers)
                {
                    if (oldUser.DocumentTypeId == user.DocumentTypeId && oldUser.DocumentId == user.DocumentId)
                    {
                        return(BadRequest());
                    }
                }
            }

            this.userDataContext.Add(user);
            this.userDataContext.SaveChanges();
            User.Data.User newUser = this.userDataContext.Users.AsNoTracking().Where(newU => newU.DocumentTypeId == user.DocumentTypeId && newU.DocumentId == user.DocumentId).First();
            return(Json(newUser));
        }
Beispiel #2
0
        public IActionResult Delete(int id)
        {
            if (id <= 0)
            {
                return(NotFound());
            }

            User.Data.User user = this.userDataContext.Users.AsNoTracking().Where(u => u.Id == id).First();

            if (user == null)
            {
                return(NotFound());
            }

            this.userDataContext.Users.Remove(user);
            this.userDataContext.SaveChanges();
            return(Ok());
        }
Beispiel #3
0
        public IActionResult GetEmails(int id)
        {
            if (id <= 0)
            {
                return(NotFound());
            }

            User.Data.User user = this.userDataContext.Users.AsNoTracking().Where(u => u.Id == id).First();

            if (user == null)
            {
                return(NotFound());
            }

            var emails = this.userDataContext.Emails.Where(email => email.UserId == id).ToList();

            return(Json(emails));
        }
Beispiel #4
0
        public IActionResult Put(int id, [FromBody] User.Data.User user)
        {
            if (id <= 0)
            {
                return(NotFound());
            }

            if (!ModelState.IsValid)
            {
                var message = string.Join(" | ", ModelState.Values
                                          .SelectMany(v => v.Errors)
                                          .Select(e => e.ErrorMessage));

                return(BadRequest(message));
            }
            else
            {
                User.Data.User oldU = this.userDataContext.Users.AsNoTracking().Where(u => u.Id == id).First();

                if (oldU == null)
                {
                    return(NotFound());
                }
            }

            List <User.Data.User> oldUsers = this.userDataContext.Users.AsNoTracking().Where(old => old.DocumentTypeId == user.DocumentTypeId && old.DocumentId == user.DocumentId).ToList();

            if (oldUsers.Count() > 0)
            {
                foreach (var oldUser in oldUsers)
                {
                    if (oldUser.Id != user.Id && oldUser.DocumentTypeId == user.DocumentTypeId && oldUser.DocumentId == user.DocumentId)
                    {
                        return(BadRequest());
                    }
                }
            }

            this.userDataContext.Users.Update(user);
            this.userDataContext.SaveChanges();
            return(Ok());
        }