示例#1
0
        // POST api/<controller>
        public HttpResponseMessage Post([FromBody] Models.User value)
        {
            return(PostBase(delegate
            {
                User user = new User()
                {
                    Username = value.Username,
                    Password = value.Password,
                    FirstName = value.FirstName,
                    LastName = value.LastName,
                    Email = value.Email,
                    PhoneNumber = value.PhoneNumber,
                    PermissionId = value.PermissionId
                };
                RegisterServiceResponse registerServiceResponse = registerService.Register(user);
                switch (registerServiceResponse)
                {
                case RegisterServiceResponse.SuccessRegister:
                    return new HttpResponseMessage(HttpStatusCode.OK);

                case RegisterServiceResponse.DuplicateUsername:
                    return Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Istnieje juz użykownik o podanej nazwie");

                case RegisterServiceResponse.DuplicateEmail:
                    return Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Istnieje juz użykownik o podanym emailu");

                case RegisterServiceResponse.ErrorRegister:
                    return Request.CreateErrorResponse(HttpStatusCode.InternalServerError, "Nieoczekiwany bład");

                default:
                    return Request.CreateErrorResponse(HttpStatusCode.InternalServerError, "Nieoczekiwany bład");
                }
            }));
        }
        /// <summary>
        /// Creates a response message to a RegisterServiceRequest message.
        /// </summary>
        /// <param name="Request">RegisterServiceRequest message for which the response is created.</param>
        /// <returns>RegisterServiceResponse message that is ready to be sent.</returns>
        public Message CreateRegisterServiceResponse(Message Request)
        {
            RegisterServiceResponse registerServiceResponse = new RegisterServiceResponse();

            Message res = CreateLocalServiceOkResponse(Request);

            res.Response.LocalService.RegisterService = registerServiceResponse;

            return(res);
        }
示例#3
0
        /// <summary>
        /// Creates a response message to a RegisterServiceRequest message.
        /// </summary>
        /// <param name="Request">RegisterServiceRequest message for which the response is created.</param>
        /// <returns>RegisterServiceResponse message that is ready to be sent.</returns>
        public LocProtocolMessage CreateRegisterServiceResponse(LocProtocolMessage Request, GpsLocation Location)
        {
            RegisterServiceResponse registerServiceResponse = new RegisterServiceResponse();

            registerServiceResponse.Location = new Iop.Locnet.GpsLocation()
            {
                Latitude  = Location.GetLocationTypeLatitude(),
                Longitude = Location.GetLocationTypeLongitude()
            };

            LocProtocolMessage res = CreateLocalServiceOkResponse(Request);

            res.Response.LocalService.RegisterService = registerServiceResponse;

            return(res);
        }
        public void Register_TryAddNewUserWithAlreadyUseUsername_ReturnResponseDuplicateUsername()
        {
            //Arrange
            string alreadyUsername = It.IsAny <string>();
            Expression <Func <User, bool> > expr = u => u.Username == alreadyUsername;

            userRepositoryMock.Setup(urm => urm.Any(It.Is <Expression <Func <User, bool> > >(x => LambdaCompare.Eq(x, expr))))
            .Returns(true);
            //Act
            RegisterServiceResponse result = registerService.Register(new User()
            {
                Username = alreadyUsername
            });

            //Assert
            result.Should().Be(RegisterServiceResponse.DuplicateUsername);
        }