public ActionResult Create(string editAction, string personalId)
        {
            PersonalDTO personalDTO = new PersonalDTO();

            try
            {
                switch (editAction)
                {
                case EditActionConstant.NEW:
                    ViewBag.Title = "Nuevo Personal";
                    personalDTO.FechaNacimiento = DateTime.Now;
                    personalDTO.EditAction      = editAction;
                    break;

                case EditActionConstant.EDIT:
                    ViewBag.Title          = "Editar Personal";
                    personalDTO            = _personalService.GetById(Convert.ToInt32(personalId));
                    personalDTO.EditAction = editAction;
                    break;
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return(PartialView(personalDTO));
        }
        public IActionResult Detail(int?id)
        {
            if (id == null)
            {
                return(RedirectToAction("Index", "Home"));
            }

            var helpers = new SelectDetails();

            var getUser         = _personalService.GetById((int)id);
            var departmantItems = helpers.GetDepartmantItems(getUser, _departmantService);
            var managerItems    = helpers.GetManagerItems(getUser, _managerService);
            var username        = _userService.GetUserId(getUser.ManagerId).Username;

            if (getUser != null)
            {
                var departmantInfo = _departmantService.GetById(getUser.DepartmantId);
                var managerInfo    = _managerService.GetById(getUser.ManagerId);

                var personalDetail = new PersonalDetailView
                {
                    Personal    = getUser,
                    Departmant  = departmantInfo,
                    Manager     = managerInfo,
                    Departmants = departmantItems,
                    Managers    = managerItems,
                    isDisabled  = username == User.Identity.Name ? true : false
                };

                return(View(personalDetail));
            }

            ViewBag.userNotFound = "User is not exist";
            return(View());
        }
        public IActionResult DeletePersonal(int?id)
        {
            if (id == null)
            {
                return(BadRequest());
            }

            var user     = _userService.GetUserByUsername(User.Identity.Name);
            var personal = _personalService.GetById((int)id);

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

            if (user.Id == personal.ManagerId)
            {
                _personalService.Delete((int)id);
                return(RedirectToAction("Index", "Home"));
            }

            return(RedirectToAction("Detail", "Personal", personal.Id));
        }
Esempio n. 4
0
 public async Task <ActionResult <PersonalDto> > GetById(int id)
 {
     return(await _personalService.GetById(id));
 }