Ejemplo n.º 1
0
        public HttpResponseMessage Post([FromBody] CoordinatorViewModel coordinator)
        {
            if (ModelState.IsValid)
            {
                var userId    = this.User.FindFirstValue(ClaimTypes.Name);
                var tempUsers = AutoMapper.Mapper.Map <Users>(coordinator);
                tempUsers.CreatedDate = DateTime.Now;
                tempUsers.Createdby   = Convert.ToInt32(userId);
                tempUsers.Password    = EncryptLib.EncryptText(coordinator.Password);
                _users.InsertUsers(tempUsers);
                var tempCoordinator = AutoMapper.Mapper.Map <Coordinator>(coordinator);
                tempCoordinator.UserId = tempUsers.UserId;
                _coordinator.InsertCoordinator(tempCoordinator);
                UsersInRoles usersInRoles = new UsersInRoles();
                usersInRoles.RoleId = 4;
                usersInRoles.UserId = tempCoordinator.UserId;
                _usersInRoles.AssignRole(usersInRoles);

                var response = new HttpResponseMessage()
                {
                    StatusCode = HttpStatusCode.OK
                };

                return(response);
            }
            else
            {
                var response = new HttpResponseMessage()
                {
                    StatusCode = HttpStatusCode.BadRequest
                };

                return(response);
            }
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> Post([FromBody] UsersInRoles usersInRoles)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    if (_usersInRoles.CheckRoleExists(usersInRoles))
                    {
                        var response = new HttpResponseMessage()
                        {
                            StatusCode = HttpStatusCode.Conflict
                        };

                        // return response;
                        return(BadRequest("Role Already Exists"));
                    }
                    else
                    {
                        usersInRoles.UserRolesId = 0;
                        _usersInRoles.AssignRole(usersInRoles);

                        var response = new HttpResponseMessage()
                        {
                            StatusCode = HttpStatusCode.OK
                        };

                        // return response;
                        return(Ok());
                    }
                }
                else
                {
                    var response = new HttpResponseMessage()
                    {
                        StatusCode = HttpStatusCode.BadRequest
                    };

                    //return response;
                    return(BadRequest());
                }
            }
            catch (Exception)
            {
                throw;
            }
        }
Ejemplo n.º 3
0
        public HttpResponseMessage Post([FromBody] UsersInRoles usersInRoles)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    if (_usersInRoles.CheckRoleExists(usersInRoles))
                    {
                        var response = new HttpResponseMessage()
                        {
                            StatusCode = HttpStatusCode.Conflict
                        };

                        return(response);
                    }
                    else
                    {
                        usersInRoles.UserRolesId = 0;
                        _usersInRoles.AssignRole(usersInRoles);

                        var response = new HttpResponseMessage()
                        {
                            StatusCode = HttpStatusCode.OK
                        };

                        return(response);
                    }
                }
                else
                {
                    var response = new HttpResponseMessage()
                    {
                        StatusCode = HttpStatusCode.BadRequest
                    };

                    return(response);
                }
            }
            catch (Exception)
            {
                throw;
            }
        }
        public HttpResponseMessage Post([FromBody] TeacherViewModel teacher)
        {
            if (ModelState.IsValid)
            {
                int userId    = Convert.ToInt32(this.User.FindFirstValue(ClaimTypes.Name));
                int coorid    = _coordinator.GetCoordinatorId(userId);
                var tempUsers = AutoMapper.Mapper.Map <Users>(teacher);
                tempUsers.CreatedDate = DateTime.Now;
                tempUsers.Createdby   = userId;
                tempUsers.Password    = EncryptLib.EncryptText(teacher.Password);
                _users.InsertUsers(tempUsers);
                var tempTeacher = AutoMapper.Mapper.Map <Teacher>(teacher);
                tempTeacher.DepartmentId = _coordinator.GetCoordinatorDepartmentId(coorid);
                tempTeacher.CreatedBy    = coorid;
                tempTeacher.UserID       = tempUsers.UserId;
                _teacher.InsertTeacher(tempTeacher);
                UsersInRoles usersInRoles = new UsersInRoles();
                usersInRoles.RoleId = 3;
                usersInRoles.UserId = tempTeacher.UserID;
                _usersInRoles.AssignRole(usersInRoles);

                var response = new HttpResponseMessage()
                {
                    StatusCode = HttpStatusCode.OK
                };

                return(response);
            }
            else
            {
                var response = new HttpResponseMessage()
                {
                    StatusCode = HttpStatusCode.BadRequest
                };

                return(response);
            }
        }
Ejemplo n.º 5
0
        public IActionResult Post([FromBody] UsersInRoles usersInRoles)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    if (_usersInRoles.CheckRoleExists(usersInRoles))
                    {
                        return(Conflict());
                    }

                    usersInRoles.UserRolesId = 0;
                    bool result = _usersInRoles.AssignRole(usersInRoles);
                    return(Ok(result));
                }

                return(BadRequest());
            }
            catch (Exception)
            {
                throw;
            }
        }