Example #1
0
        public async Task <IActionResult> PostCoordinator([FromBody] Common.Models.Coordinator coordinator)
        {
            if (!ModelState.IsValid)
            {
                return(this.BadRequest(ModelState));
            }
            var user = await this.userHelper.GetUserByEmailAsync(coordinator.UserName);

            if (user == null)
            {
                user = new User
                {
                    FirstName   = coordinator.FirstName,
                    LastName    = coordinator.LastName,
                    PhoneNumber = coordinator.PhoneNumber,
                    UserName    = coordinator.UserName,
                    Email       = coordinator.UserName,
                    Enrollment  = coordinator.Enrollment
                };
                var result = await this.userHelper.AddUserAsync(user, coordinator.Password);

                if (!result.Succeeded)
                {
                    return(this.BadRequest(ModelState));
                }
            }
            else
            {
                return(this.BadRequest(ModelState));
            }
            await this.userHelper.AddUserToRoleAsync(user, "Coordinator");

            var coordinatorEntity = new Coordinator
            {
                HireDate = coordinator.HireDate,
                //TODO: Imagen
                User = user
            };
            var coordinatorNew = await coordinatorRepository.CreateAsync(coordinatorEntity);

            return(Ok(coordinatorNew));
        }
Example #2
0
        public async Task <IActionResult> PutCoordinator([FromRoute] int id, [FromBody] Common.Models.Coordinator coordinator)
        {
            if (!ModelState.IsValid)
            {
                return(this.BadRequest(ModelState));
            }

            if (id != coordinator.Id)
            {
                return(this.BadRequest("Error Id"));
            }

            var user = await this.userHelper.GetUserByEmailAsync(coordinator.UserName);

            if (user == null)
            {
                return(this.BadRequest("Usuario No Existe"));
            }

            user.FirstName   = coordinator.FirstName;
            user.LastName    = coordinator.LastName;
            user.PhoneNumber = coordinator.PhoneNumber;
            user.Enrollment  = coordinator.Enrollment;

            Coordinator coordinatorOld = await this.coordinatorRepository.GetCoordinatorByIDWithUser(id);

            if (coordinatorOld == null)
            {
                return(this.BadRequest("coordinator don't exist"));
            }

            coordinatorOld.HireDate = coordinator.HireDate;
            // TODO: Imagen teacherOld.ImageUrl
            coordinatorOld.User = user;


            //TODO: actualizar imagen
            Coordinator coordinatorUpdate = await this.coordinatorRepository.UpdateAsync(coordinatorOld);

            return(Ok(coordinatorUpdate));
        }