public IHttpActionResult Patch(UserViewModel model)
        {
            if (!model.id.HasValue || model.id.Value < 0)
            {
                return(BadRequest());
            }

            var svc      = new UserAppSvcGeneric();
            var toUpdate = svc.Get(model.id.Value);

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

            try {
                toUpdate.Name = model.name;
                var result = svc.Update(toUpdate);

                return(Ok(result));
            }
            catch (Exception ex) {
                return(InternalServerError(ex));
            }
        }
示例#2
0
        private bool DoCreateUser(UserAccountViewModel model)
        {
            var svc     = new UserAppSvcGeneric();
            var created = svc.Create(model.GetEntity());

            return(created.Id > 0);
        }
示例#3
0
        private bool DoUpdateUser(UserAccountViewModel model)
        {
            var svc     = new UserAppSvcGeneric();
            var updated = svc.Update(model.GetEntity());

            return(updated != null);
        }
示例#4
0
        public ActionResult Delete(int id)
        {
            var service = new UserAppSvcGeneric();
            var delete  = service.Delete(id);

            return(RedirectToAction("List"));
        }
示例#5
0
        public IHttpActionResult Post(UserViewModel model)
        {
            if (string.IsNullOrEmpty(model.login) ||
                string.IsNullOrEmpty(model.name) ||
                string.IsNullOrEmpty(model.email) ||
                string.IsNullOrEmpty(model.password))
            {
                return(BadRequest());
            }

            try
            {
                var svc      = new UserAppSvcGeneric();
                var toCreate = model.GetUser();
                var result   = svc.Create(toCreate);
                if (result.Id > 0)
                {
                    return(Ok(result));
                }

                return(BadRequest());
            }
            catch (Exception ex)
            {
                return(InternalServerError(ex));
            }
        }
示例#6
0
        public void FindByTestGetAll()
        {
            var svc    = new UserAppSvcGeneric();
            var result = svc.FindBy(null);

            Assert.IsNotNull(result);
            Assert.IsTrue(result.Count() > 0);
        }
示例#7
0
        public IEnumerable <User> GetUserFiltered(string name, int userTypeId)
        {
            var svc    = new UserAppSvcGeneric();
            var result = svc.FindBy(new User {
                Name = name, UserTypeId = userTypeId
            });

            return(result);
        }
示例#8
0
        public ActionResult List()
        {
            var service  = new UserAppSvcGeneric();
            var listUser = service.FindBy(null);

            ViewBag.listUser = listUser;

            return(View());
        }
示例#9
0
        public void FindByTestGetByUserTypeNameInvalido()
        {
            var svc    = new UserAppSvcGeneric();
            var result = svc.FindBy(new User {
                UserTypeId = 1, Name = "common"
            });

            Assert.IsNotNull(result);
            Assert.IsTrue(result.Count() == 0);
        }
示例#10
0
        public void FindByTestGetByUserType()
        {
            var svc    = new UserAppSvcGeneric();
            var result = svc.FindBy(new User {
                UserTypeId = 1
            });

            Assert.IsNotNull(result);
            Assert.IsTrue(result.Count() > 0);
        }
示例#11
0
        public void FindByTestGetByName()
        {
            var svc    = new UserAppSvcGeneric();
            var result = svc.FindBy(new User {
                Name = "common"
            });

            Assert.IsNotNull(result);
            Assert.IsTrue(result.Count() > 0);
        }
示例#12
0
        public IHttpActionResult Get(User filter)
        {
            var svc    = new UserAppSvcGeneric();
            var result = svc.FindBy(filter);

            if (result == null || result.Count() == 0)
            {
                return(NotFound());
            }
            return(Ok(result));
        }
示例#13
0
        public void UpdateTest()
        {
            var svc      = new UserAppSvcGeneric();
            var toUpdate = new User {
                Id = 2, Name = "New Name For Common"
            };
            var updated = svc.Update(toUpdate);

            Assert.IsNotNull(updated);
            Assert.AreEqual(toUpdate.Id, updated.Id);
            Assert.AreEqual(toUpdate.Name, updated.Name);
        }
示例#14
0
        private UserAccountViewModel GetViewModelForEdit(int id)
        {
            var user = new UserAppSvcGeneric().Get(id);

            return(new UserAccountViewModel
            {
                EmailUsuario = user.Email,
                LoginUsuario = user.Login,
                NomeUsuario = user.Name,
                IsEdit = true,
                Id = id
            });
        }
示例#15
0
        public JsonResult Delete(int id)
        {
            var svc      = new UserAppSvcGeneric();
            var toDelete = svc.Get(id);

            if (toDelete == null)
            {
                return(Json(new { IsSuccess = false, Message = "Usuário Inválido" }));
            }
            if (svc.Delete(id))
            {
                return(Json(new { IsSuccess = true }));
            }
            return(Json(new { IsSuccess = false, Message = "Erro ao Excluir Usuário" }));
        }
示例#16
0
        public IHttpActionResult List(string name, int?usertypeid)
        {
            var svc       = new UserAppSvcGeneric();
            var filterObj = new User
            {
                Name       = name,
                UserTypeId = usertypeid ?? 0
            };

            var result = svc.FindBy(filterObj);

            if (result == null || result.Count() == 0)
            {
                return(NotFound());
            }
            return(Ok(result));
        }
示例#17
0
        public ActionResult Index(string login, string password, string returnUrl)
        {
            var svc    = new UserAppSvcGeneric();
            var result = svc.Authenticate(login, password);

            if (result != null)
            {
                HttpContext.Session["CurrentUser"] = result;
                if (string.IsNullOrEmpty(returnUrl))
                {
                    return(RedirectToAction("Index", "Home"));
                }
                return(Redirect(returnUrl));
            }
            ViewBag.LoginError = "Usuário ou senha inválidos";
            return(View());
        }
        public IHttpActionResult List(string name, int?userTypeId)
        {
            var svc = new UserAppSvcGeneric();

            var filter = new User {
                Name       = name,
                UserTypeId = userTypeId ?? 0 // ?? teste se o resultado é nulo
            };

            var result = svc.FindBy(filter);

            if (result == null || result.Count() == 0)
            {
                return(NotFound());
            }

            return(Ok(result));
        }
        public IHttpActionResult Delete(int id)
        {
            if (id < 0)
            {
                return(BadRequest());
            }
            var svc  = new UserAppSvcGeneric();
            var user = svc.Get(id);

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

            var result = svc.Delete(id);

            return(result ? StatusCode(HttpStatusCode.NoContent) : StatusCode(HttpStatusCode.InternalServerError));
        }
示例#20
0
        public void CreateTest()
        {
            var usr = new User
            {
                Email        = "*****@*****.**",
                IsActive     = true,
                Login        = "******",
                Name         = "New User",
                RegisterDate = DateTime.Now,
                Password     = "******",
                UserTypeId   = 1
            };
            var svc = new UserAppSvcGeneric();
            var res = svc.Create(usr);

            Assert.IsNotNull(res);
            Assert.IsTrue(res.Id > 0);
        }
示例#21
0
        public IHttpActionResult Get(int?id)
        {
            var svc = new UserAppSvcGeneric();

            if (id.HasValue && id.Value < 0)
            {
                return(BadRequest());
            }

            if (id.HasValue && id.Value > 0)
            {
                var resultSingle = svc.Get(id.Value);
                if (resultSingle.Id == 0)
                {
                    return(NotFound());
                }
                return(Ok(resultSingle));
            }
            return(BadRequest());
        }
        public ProjectUserViewModel(int projetoId)
        {
            var result = new ProjectAppSvcGeneric().Get(projetoId);

            ProjectId   = result.Id;
            ProjectName = result.ProjectName;



            var allUsers       = new UserAppSvcGeneric().FindBy(null);
            var dispUser       = allUsers.ToList();
            var usersInproject = new ProjectUserAppSvcGeneric().FindBy(new ProjetcUser {
                ProjectId = projetoId
            });

            foreach (var inProj in usersInproject)
            {
                dispUser.RemoveAll(r => r.Id == inProj.UserId);
            }
            DdlUsuarios = HelperForDropdown <User> .GetDropDownListFrom(dispUser, "Name");
        }
        public IHttpActionResult Get(int?id)
        {
            var result = new UserAppSvcGeneric().Get(id.Value);

            if (id < 0)
            {
                return(BadRequest());
            }

            if (result.IsActive == false)
            {
                return(BadRequest());
            }


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



            return(Ok(result));
        }