コード例 #1
0
        public JsonResult Hide(int id)
        {
            var result = new TaskResult();

            try
            {
                var job = _jobsService.GetById(id);
                if (job == null)
                {
                    result.AddErrorMessage("No puedes esconder un puesto que no existe.");
                }
                else if (job.UserId == _currentUser.UserId)
                {
                    job.IsHidden = !job.IsHidden;
                    result       = _jobsService.Update(job);
                }
                else
                {
                    result.AddErrorMessage("No puedes esconder un puesto que no creaste.");
                }
            }
            catch (Exception ex)
            {
                HttpContext.RiseError(ex);
                result.AddErrorMessage(ex.Message);
            }
            return(Json(result));
        }
コード例 #2
0
        public JsonResult Delete(int id)
        {
            var result = new TaskResult();

            try
            {
                var company = _companiesService.GetById(id);

                if (company == null)
                {
                    result.AddErrorMessage("No puedes eliminar una Compañia que no existe.");
                }
                else if (company.UserId != _currentUser.UserId)
                {
                    result.AddErrorMessage("No puedes eliminar una Compañia que no creaste.");
                }

                result = _companiesService.Delete(company);
            }
            catch (Exception ex)
            {
                HttpContext.RiseError(ex);
                result.AddErrorMessage(ex.Message);
            }

            return(Json(result));
        }
コード例 #3
0
        public JsonResult Delete(int id)
        {
            var result = new TaskResult();

            try
            {
                var job = _jobsService.GetById(id);

                if (job == null)
                {
                    result.AddErrorMessage("No puedes eliminar un puesto que no existe.");
                }
                else if (job.UserId == _currentUser.UserId)
                {
                    if (!job.IsActive)
                    {
                        result.AddErrorMessage("El puesto que intentas eliminar ya está eliminado.");
                    }
                    else
                    {
                        result = _jobsService.Delete(job);
                    }
                }
                else
                {
                    result.AddErrorMessage("No puedes eliminar un puesto que no creaste.");
                }
            }
            catch (Exception ex)
            {
                HttpContext.RiseError(ex);
                result.AddErrorMessage(ex.Message);
            }
            return(Json(result));
        }
コード例 #4
0
        public async Task <IActionResult> AddUserRole(AddUserRoleModel model)
        {
            var result = new TaskResult <string>();

            var userResult = await _usersRepository.GetByIdAsync(model.UserId);

            if (userResult.Data == null)
            {
                userResult.AddErrorMessage("El usuario no existe");
                return(BadRequest(userResult));
            }

            var roleResult = await _rolesRepository.GetByNameAsync(model.RoleName);

            if (roleResult.Data == null)
            {
                roleResult.AddErrorMessage("El role no existe");
                return(BadRequest(roleResult));
            }

            var added = await _usersRepository.AddUserRoleAsync(roleResult.Data.Id, userResult.Data.Id);

            if (!added)
            {
                result.AddErrorMessage($"Error al agregar el rol {model.RoleName} al usuario {userResult.Data.UserName}");
                return(Ok(result));
            }

            result.AddMessage($"Se agregó exitosamente el rol {model.RoleName} al usuario {userResult.Data.UserName}");
            return(Ok(result));
        }
コード例 #5
0
        public async Task <IActionResult> Register(Users user)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var result = new TaskResult <string>();
            var usr    = await _usersRepository.GetByUserNameAsync(user.UserName);

            if (usr == null)
            {
                var roleResult = await _rolesRepository.GetByNameAsync(RolesConstants.APPLICANT);

                if (!roleResult.Success)
                {
                    roleResult.AddErrorMessage($"El role {RolesConstants.APPLICANT} no existe");
                    return(BadRequest(roleResult));
                }

                await _usersRepository.CreateAsync(user);

                var createdSuccesfully = await _usersRepository.SaveAsync();

                if (!createdSuccesfully)
                {
                    result.AddErrorMessage($"No se pudo crear el usuario: {user.UserName}");
                    return(BadRequest(result));
                }

                var roleAdded = await _usersRepository.AddUserRoleAsync(roleResult.Data.Id, user.Id);

                if (!roleAdded)
                {
                    result.AddErrorMessage($"No se pudo agregar el rol {roleResult.Data.Name} al usuario {user.UserName}");
                    return(BadRequest(result));
                }

                result.Data = _jwtAuthenticationManager.Authenticate(user);
                return(Ok(result));
            }

            result.AddErrorMessage("El nombre de usuario ingresado ya se encuentra registrado");
            return(BadRequest(result));
        }
コード例 #6
0
ファイル: ItemService.cs プロジェクト: Edulopez/CheckoutTest
        public override TaskResult ValidateOnDelete(Item entity)
        {
            if (entity == null)
            {
                TaskResult.AddErrorMessage("Not a valid object");
            }

            return(TaskResult);
        }
コード例 #7
0
ファイル: JobsService.cs プロジェクト: ronelpanag/emplea_do
        public TaskResult ValidateOnUpdate(Job entity)
        {
            if (entity == null)
            {
                TaskResult.AddErrorMessage("La posición de trabajo que intentas eliminar no existe");
            }

            return(TaskResult);
        }
コード例 #8
0
ファイル: ItemService.cs プロジェクト: Edulopez/CheckoutTest
 public IEnumerable <Item> GetItems()
 {
     try
     {
         return(_itemRepository.GetAll());
     }
     catch (Exception ex)
     {
         TaskResult.AddErrorMessage("Could not get all");
         TaskResult.Exception = ex;
         return(null);
     }
 }
コード例 #9
0
ファイル: ItemService.cs プロジェクト: Edulopez/CheckoutTest
 public Item GetById(int id)
 {
     try
     {
         return(_itemRepository.GetById(id));
     }
     catch (Exception ex)
     {
         TaskResult.AddErrorMessage("Could not get");
         TaskResult.Exception = ex;
         return(null);
     }
 }
コード例 #10
0
ファイル: ItemService.cs プロジェクト: Edulopez/CheckoutTest
        public override TaskResult ValidateOnCreate(Item entity)
        {
            if (entity == null)
            {
                TaskResult.AddErrorMessage("Not a valid object");
            }
            else if (GetItemByName(entity.Title) != null)
            {
                TaskResult.AddErrorMessage("Title must be unique");
            }

            return(TaskResult);
        }
コード例 #11
0
ファイル: ItemService.cs プロジェクト: Edulopez/CheckoutTest
 public IEnumerable <Item> GetItems(int pageNumber = 0, int count = 1)
 {
     try
     {
         return(_itemRepository.GetByFilter(pageNumber, count, x => true));
     }
     catch (Exception ex)
     {
         TaskResult.AddErrorMessage("Could not get all");
         TaskResult.Exception = ex;
         return(null);
     }
 }
コード例 #12
0
ファイル: JobsService.cs プロジェクト: ronelpanag/emplea_do
        public TaskResult ValidateOnCreate(Job entity)
        {
            if (entity.UserId == null)
            {
                TaskResult.AddErrorMessage("La posición de trabajo debe tener un usuario asignado");
            }

            var user = _userRepository.GetById(entity.UserId.Value);

            if (user == null)
            {
                TaskResult.AddErrorMessage("El usuario especificado no existe!");
            }

            return(TaskResult);
        }
コード例 #13
0
        public async Task <TaskResult <bool> > AddTrainingsRelAsync(List <ApplicantsTrainings> applicantsTrainings)
        {
            var result = new TaskResult <bool>();

            try
            {
                await _stepCoreContext.ApplicantsTrainings.AddRangeAsync(applicantsTrainings);

                result.Data = await _stepCoreContext.SaveChangesAsync() > 0;
            }
            catch (System.Exception e)
            {
                result.AddErrorMessage("Error adding ApplicantsTrainings: " + e.InnerException.Message);
            }

            return(result);
        }
コード例 #14
0
ファイル: ItemService.cs プロジェクト: Edulopez/CheckoutTest
 public override TaskResult Delete(int entityId)
 {
     ValidateOnDelete(GetById(entityId));
     if (TaskResult.ExecutedSuccesfully)
     {
         try
         {
             _itemRepository.Remove(entityId);
             TaskResult.AddMessage("Entity deleted");
         }
         catch (Exception ex)
         {
             TaskResult.AddErrorMessage("Could not delete");
             TaskResult.Exception = ex;
         }
     }
     return(TaskResult);
 }
コード例 #15
0
ファイル: JobsService.cs プロジェクト: ronelpanag/emplea_do
 public TaskResult Create(Job entity)
 {
     ValidateOnCreate(entity);
     if (TaskResult.ExecutedSuccesfully)
     {
         try
         {
             _jobsRepository.Insert(entity);
             _jobsRepository.CommitChanges();
         }
         catch (Exception ex)
         {
             TaskResult.Exception = ex;
             TaskResult.AddErrorMessage(ex.Message);
         }
     }
     return(TaskResult);
 }
コード例 #16
0
ファイル: ItemService.cs プロジェクト: Edulopez/CheckoutTest
 public override TaskResult Create(Item entity)
 {
     ValidateOnCreate(entity);
     if (TaskResult.ExecutedSuccesfully)
     {
         try
         {
             _itemRepository.Add(entity);
             TaskResult.AddMessage("Entity created");
         }
         catch (Exception ex)
         {
             TaskResult.AddErrorMessage("Could not create");
             TaskResult.Exception = ex;
         }
     }
     return(TaskResult);
 }
コード例 #17
0
        public async Task <IActionResult> Update([Required] int id, Applicants applicants)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            var result = new TaskResult <Applicants>();

            if (id != applicants.Id)
            {
                result.AddErrorMessage("Los identificadores no coinciden");
                return(Ok(result));
            }

            result = _applicantsRepository.Update(applicants);
            await _applicantsRepository.SaveAsync();

            return(Ok(result));
        }
コード例 #18
0
        new public async Task <TaskResult <int> > CreateAsync(Applicants applicants)
        {
            var result = new TaskResult <int>();

            try
            {
                await _stepCoreContext.AddAsync(applicants);

                await _stepCoreContext.SaveChangesAsync();

                result.Data = applicants.Id;
            }
            catch (System.Exception e)
            {
                result.AddErrorMessage("Error adding applicant: " + e.InnerException.Message);
            }

            return(result);
        }
コード例 #19
0
ファイル: JobsService.cs プロジェクト: ronelpanag/emplea_do
        public TaskResult Delete(int entityId)
        {
            var entity = _jobsRepository.GetById(entityId);

            ValidateOnDelete(entity);
            if (TaskResult.ExecutedSuccesfully)
            {
                try
                {
                    _jobsRepository.SoftDelete(entityId);
                    _jobsRepository.CommitChanges();
                }
                catch (Exception ex)
                {
                    TaskResult.Exception = ex;
                    TaskResult.AddErrorMessage(ex.Message);
                }
            }
            return(TaskResult);
        }
コード例 #20
0
ファイル: ItemService.cs プロジェクト: Edulopez/CheckoutTest
 public Item GetItemByName(string itemName)
 {
     if (string.IsNullOrEmpty(itemName))
     {
         return(null);
     }
     if (!SanitizerHelper.IsClean(itemName))
     {
         return(null);
     }
     try
     {
         return(_itemRepository.GetByFilter(0, 1, x => x.Title.ToLower() == itemName.ToLower()).FirstOrDefault());
     }
     catch (Exception ex)
     {
         TaskResult.AddErrorMessage("Could not get");
         TaskResult.Exception = ex;
         return(null);
     }
 }
コード例 #21
0
        public async Task <IActionResult> Create(Applicants applicants)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var resultApplicant = await _applicantsRepository.GetByIdAsync(applicants.Id);

            var applicant   = resultApplicant.Data;
            var newEmployee = new Employees();

            if (resultApplicant.Success)
            {
                applicant.Status = (int)Enums.Entities.Status.DISABLE;
                _applicantsRepository.Update(applicant);

                newEmployee.JobPositionsId  = applicant.JobPositionsId;
                newEmployee.MonthSalary     = applicant.SalaryAspiration;
                newEmployee.Name            = applicant.Name;
                newEmployee.DocumentNumber  = applicant.DocumentNumber;
                newEmployee.DateOfAdmission = DateTime.Now;
                newEmployee.Department      = applicant.Department;
            }
            var result = new TaskResult <bool>();

            try
            {
                await _genericRepository.CreateAsync(newEmployee);

                result.Data = await _genericRepository.SaveAsync();
            }
            catch (Exception e)
            {
                result.AddErrorMessage(e.Message);
            }

            return(Ok(result));
        }
コード例 #22
0
        public async Task <IActionResult> Login(Users user)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(new BadRequestObjectResult(ModelState)));
            }

            var usr = await _usersRepository.GetByUserNameAsync(user.UserName);

            var result = new TaskResult <string>();

            if (usr != null)
            {
                if (usr.Password == user.Password)
                {
                    result.Data = _jwtAuthenticationManager.Authenticate(usr);
                    return(Ok(result));
                }
            }

            result.AddErrorMessage("Usuario y/o password inválido");
            return(Unauthorized(result));
        }
コード例 #23
0
ファイル: JobsService.cs プロジェクト: ronelpanag/emplea_do
        public TaskResult Update(Job updatedJob)
        {
            var oldEntity = _jobsRepository.GetById(updatedJob.Id);

            ValidateOnUpdate(updatedJob);
            if (TaskResult.ExecutedSuccesfully)
            {
                try
                {
                    oldEntity.Title           = updatedJob.Title;
                    oldEntity.Approved        = updatedJob.Approved;
                    oldEntity.Category        = updatedJob.Category;
                    oldEntity.Company.Email   = updatedJob.Company.Email;
                    oldEntity.Company.LogoUrl = updatedJob.Company.LogoUrl;
                    oldEntity.Company.Name    = updatedJob.Company.Name;
                    oldEntity.Company.Url     = updatedJob.Company.Url;
                    oldEntity.Description     = updatedJob.Description;
                    oldEntity.HowToApply      = updatedJob.HowToApply;
                    oldEntity.IsActive        = updatedJob.IsActive;
                    oldEntity.IsRemote        = updatedJob.IsRemote;

                    if (updatedJob.Location != null)
                    {
                        oldEntity.Location = oldEntity.Location == null
                            ? new Location()
                            : oldEntity.Location;

                        oldEntity.Location.Latitude  = updatedJob.Location.Latitude;
                        oldEntity.Location.Longitude = updatedJob.Location.Longitude;
                        oldEntity.Location.Name      = updatedJob.Location.Name;
                        oldEntity.Location.PlaceId   = updatedJob.Location.PlaceId;
                    }

                    oldEntity.HireType = updatedJob.HireType;
                    if (updatedJob.JoelTest != null)
                    {
                        oldEntity.JoelTest = oldEntity.JoelTest == null
                            ? new JoelTest()
                            : oldEntity.JoelTest;

                        oldEntity.JoelTest.HasBestTools               = updatedJob.JoelTest.HasBestTools;
                        oldEntity.JoelTest.HasBugDatabase             = updatedJob.JoelTest.HasBugDatabase;
                        oldEntity.JoelTest.HasBusFixedBeforeProceding = updatedJob.JoelTest.HasBusFixedBeforeProceding;
                        oldEntity.JoelTest.HasDailyBuilds             = updatedJob.JoelTest.HasDailyBuilds;
                        oldEntity.JoelTest.HasHallwayTests            = updatedJob.JoelTest.HasHallwayTests;
                        oldEntity.JoelTest.HasOneStepBuilds           = updatedJob.JoelTest.HasOneStepBuilds;
                        oldEntity.JoelTest.HasQuiteEnvironment        = updatedJob.JoelTest.HasQuiteEnvironment;
                        oldEntity.JoelTest.HasSourceControl           = updatedJob.JoelTest.HasSourceControl;
                        oldEntity.JoelTest.HasSpec             = updatedJob.JoelTest.HasSpec;
                        oldEntity.JoelTest.HasTesters          = updatedJob.JoelTest.HasTesters;
                        oldEntity.JoelTest.HasUpToDateSchedule = updatedJob.JoelTest.HasUpToDateSchedule;
                        oldEntity.JoelTest.HasWrittenTest      = updatedJob.JoelTest.HasWrittenTest;
                    }
                    _jobsRepository.Update(oldEntity);
                    _jobsRepository.CommitChanges();
                }
                catch (Exception ex)
                {
                    TaskResult.Exception = ex;
                    TaskResult.AddErrorMessage(ex.Message);
                }
            }
            return(TaskResult);
        }