Пример #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);
            }
        }