コード例 #1
0
        public InterfaceResponse UpdateRegister(RegisterUpdateRequest request)
        {
            Logger.Debug("Registration details received: {0}",
                         JsonConvert.SerializeObject(request, Formatting.Indented));

            var userPrincipal = new UserPrincipal(ClaimsPrincipal.Current);

            if (userPrincipal.Id.HasValue)
            {
                InterfaceResponse response;
                //use in built data annotations to ensure model has
                //binded correctly
                if (!ModelState.IsValid)
                {
                    var errors = ModelState.Keys.SelectMany(key =>
                                                            ModelState[key].Errors.Select(x => x.ErrorMessage));
                    response = new InterfaceResponse
                    {
                        Success = false,
                        Message = "Form has validation errors",
                        Errors  = errors.ToArray()
                    };
                }
                else
                {
                    //send request to the user service and return the
                    //response (success or fail)
                    response = UserService.UpdateRegistration(
                        request, userPrincipal.Id.Value);
                }
                Logger.Debug("Registration update sent Response: {0}",
                             JsonConvert.SerializeObject(
                                 response, Formatting.Indented));
                return(response);
            }
            else
            {
                var response = new InterfaceResponse
                {
                    Success = false,
                    Message = "Invalid user ID",
                    Errors  = new[] { "No user is logged on" }
                };
                Logger.Debug("The user ID session is invalid",
                             JsonConvert.SerializeObject(
                                 response, Formatting.Indented));
                return(response);
            }
        }
コード例 #2
0
        public InterfaceResponse UpdateRegistration(RegisterUpdateRequest request, int accountId)
        {
            //this function allows the user to send their new rego details
            //to update their account

            var user = UserRepository.Find(accountId);

            //check user is real
            if (user == null)
            {
                return new InterfaceResponse
                       {
                           Success = false,
                           Message = $"User account {accountId} does not exist"
                       }
            }
            ;

            var record = RegistrationRepository.Find(accountId);


            if (record == null)
            {
                //create a new record if no record exists currently
                var registration = new Registration
                {
                    AccountID           = user.AccountID,
                    AddressLine1        = request.AddressLine1,
                    AddressLine2        = request.AddressLine2,
                    DriversLicenceID    = request.LicenceNumber,
                    DriversLicenceState = request.LicenceState,
                    PhoneNumber         = request.PhoneNumber,
                    Postcode            = request.Postcode,
                    State  = request.State,
                    Suburb = request.Suburb
                };

                RegistrationRepository.Add(registration);
            }
            else
            {
                //if a record exists override existing values
                record.AccountID = user.AccountID;
                user.FirstName   = request.FirstName;
                user.LastName    = request.LastName;
                //user.Email = request.Email;
                record.AddressLine1        = request.AddressLine1;
                record.AddressLine2        = request.AddressLine2;
                record.DriversLicenceID    = request.LicenceNumber;
                record.DriversLicenceState = request.LicenceState;
                record.PhoneNumber         = request.PhoneNumber;
                record.Postcode            = request.Postcode;
                record.State  = request.State;
                record.Suburb = request.Suburb;
                UserRepository.Update(user);
                RegistrationRepository.Update(record);
            }

            return(new InterfaceResponse
            {
                Success = true,
                Message = "Registration record updated"
            });
        }