Exemple #1
0
        public IEnumerable <DTOUser> GetAll()
        {
            BusinessLogic.Controllers.UserController controller = new BusinessLogic.Controllers.UserController();
            List <DTOUser> users = controller.GetAll();

            return(users);
        }
Exemple #2
0
        public IHttpActionResult DeleteUser(string id)
        {
            DTOBaseResponse response = new DTOBaseResponse();

            try
            {
                var identity      = (ClaimsIdentity)User.Identity;
                var identity_mail = identity.Claims.Where(c => c.Type == ClaimTypes.Email)
                                    .Select(c => c.Value).SingleOrDefault();

                if (id == identity_mail)
                {
                    BusinessLogic.Controllers.UserController controller = new BusinessLogic.Controllers.UserController();
                    controller.DeleteUser(id);
                    response.Success = true;
                }
                else
                {
                    response.Success = false;
                }
            }
            catch (Exception ex)
            {
                response.Success = false;
                response.Error   = ex.ToString();
            }
            return(Ok(response));
        }
Exemple #3
0
        public IHttpActionResult GetUser(string id)
        {
            BusinessLogic.Controllers.UserController controller = new BusinessLogic.Controllers.UserController();
            var user = controller.GetUser(id);

            if (user == null)
            {
                return(NotFound());
            }
            return(Ok(user));
        }
Exemple #4
0
        public IHttpActionResult CreateUser(DTOUser user)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            DTOBaseResponse response = new DTOBaseResponse();

            try
            {
                BusinessLogic.Controllers.UserController controller = new BusinessLogic.Controllers.UserController();
                controller.CreateUser(user);
                response.Success = true;
            }
            catch (Exception ex)
            {
                response.Success = false;
                response.Error   = ex.ToString();
            }
            return(Ok(response));
        }
Exemple #5
0
        public IHttpActionResult UpdateUser(string id, DTOUser user)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var identity      = (ClaimsIdentity)User.Identity;
            var identity_mail = identity.Claims.Where(c => c.Type == ClaimTypes.Email)
                                .Select(c => c.Value).SingleOrDefault();

            if ((id != user.loginnameUser) && (id != identity_mail))
            {
                return(BadRequest());
            }

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            DTOBaseResponse response = new DTOBaseResponse();

            try
            {
                BusinessLogic.Controllers.UserController controller = new BusinessLogic.Controllers.UserController();
                controller.UpdateUser(id, user);
                response.Success = true;
            }
            catch (Exception ex)
            {
                response.Success = false;
                response.Error   = ex.ToString();
            }
            return(Ok(response));
        }