예제 #1
0
        public Status<UserInterest> SendApplication(string username, int userInterestId, UserApplication application)
        {
            if (string.IsNullOrWhiteSpace(username))
                return Status.ValidationError<UserInterest>(null, "username", "The username is required");

            // validate UserApplication
            var appStatusValid = Status.Validatate<UserApplication>(application);

            if (appStatusValid.StatusCode != 200)
                return Status.ValidationError<UserInterest>(null, "application", "The application is not valid");

            // update user application
            var appStatusSave = SaveApplicationForUser(username, application);

            if (appStatusSave.StatusCode != 200)
                return Status.Error<UserInterest>("System was unable to update application", null);

            using (RentlerContext context = new RentlerContext())
            {
                try
                {
                    // get lead
                    var lead = (from i in context.UserInterests
                                where i.User.Username == username && i.UserInterestId == userInterestId
                                select i).SingleOrDefault();

                    if (lead == null)
                        return Status.NotFound<UserInterest>();

                    // update lead - ApplicationSubmitted = true
                    lead.ApplicationSubmitted = true;

                    context.SaveChanges();

                    EmailSendApplicationModel model = new EmailSendApplicationModel(lead);
                    mailer.SendApplication(model);

                    return Status.OK(lead);
                }
                catch (Exception ex)
                {
                    // log exception
                    return Status.Error<UserInterest>("System was unable to get lead", null);
                }
            }
        }
예제 #2
0
        /// <summary>
        /// Sets the application for user.
        /// </summary>
        /// <param name="username">The username of the user to set the application for.</param>
        /// <param name="userApplication">The user's application.</param>
        /// <returns>
        /// The user application that was saved.
        /// </returns>
        public Status<UserApplication> SaveApplicationForUser(
			string username, UserApplication userApplication)
        {
            var identity = CustomAuthentication.GetIdentity();

            if (!identity.IsAuthenticated)
                return Status.UnAuthorized<UserApplication>();

            using (var context = new RentlerContext())
            {
                try
                {
                    bool isNew = false;

                    var application = (from u in context.UserApplications
                                       where u.UserId == identity.UserId
                                       select u).SingleOrDefault();

                    if (application == null)
                    {
                        application = new UserApplication { UserId = identity.UserId };
                        isNew = true;
                    }

                    application.ConvictedExplaination = userApplication.ConvictedExplaination;
                    application.EmergencyContact = userApplication.EmergencyContact;
                    application.EmergencyContactAddressLine1 = userApplication.EmergencyContactAddressLine1;
                    application.EmergencyContactAddressLine2 = userApplication.EmergencyContactAddressLine2;
                    application.EmergencyContactCity = userApplication.EmergencyContactCity;
                    application.EmergencyContactPhone = userApplication.EmergencyContactPhone;
                    application.EmergencyContactState = userApplication.EmergencyContactState;
                    application.EmergencyContactZip = userApplication.EmergencyContactZip;
                    application.FirstName = userApplication.FirstName;
                    application.HasBeenConvicted = userApplication.HasBeenConvicted;
                    application.HasEverBeenUnlawfulDetainer = userApplication.HasEverBeenUnlawfulDetainer;
                    application.LastName = userApplication.LastName;
                    application.PresentAddressLine1 = userApplication.PresentAddressLine1;
                    application.PresentAddressLine2 = userApplication.PresentAddressLine2;
                    application.PresentCity = userApplication.PresentCity;
                    application.PresentEmployer = userApplication.PresentEmployer;
                    application.PresentEmployerPhone = userApplication.PresentEmployerPhone;
                    application.PresentLandlord = userApplication.PresentLandlord;
                    application.PresentLandlordPhone = userApplication.PresentLandlordPhone;
                    application.PresentPhone = userApplication.PresentPhone;
                    application.PresentState = userApplication.PresentState;
                    application.PresentZip = userApplication.PresentZip;
                    application.PreviousAddressLine1 = userApplication.PreviousAddressLine1;
                    application.PreviousAddressLine2 = userApplication.PreviousAddressLine2;
                    application.PreviousCity = userApplication.PreviousCity;
                    application.PreviousEmployer = userApplication.PreviousEmployer;
                    application.PreviousEmployerPhone = userApplication.PreviousEmployerPhone;
                    application.PreviousLandlord = userApplication.PreviousLandlord;
                    application.PreviousLandlordPhone = userApplication.PreviousLandlordPhone;
                    application.PreviousState = userApplication.PreviousState;
                    application.PreviousZip = userApplication.PreviousZip;
                    application.Ssn = userApplication.Ssn;
                    application.UpdateDateUtc = DateTime.UtcNow;
                    application.UpdatedBy = "accountadapter";
                    application.VehicleColor = userApplication.VehicleColor;
                    application.VehicleLicenseNumber = userApplication.VehicleLicenseNumber;
                    application.VehicleMake = userApplication.VehicleMake;
                    application.VehicleModel = userApplication.VehicleModel;
                    application.VehicleState = userApplication.VehicleState;
                    application.VehicleYear = userApplication.VehicleYear;

                    // new applications need to be added to the context
                    if (isNew)
                        context.UserApplications.Add(application);

                    context.SaveChanges();

                    return Status.OK<UserApplication>(application);
                }
                catch (Exception ex)
                {
                    // TODO: log exception
                    return Status.Error<UserApplication>("System was unable to create/update application", null);
                }
            }
        }
예제 #3
0
 /// <summary>
 /// Create a new UserApplication object.
 /// </summary>
 /// <param name="userId">Initial value of the UserId property.</param>
 /// <param name="hasBeenConvicted">Initial value of the HasBeenConvicted property.</param>
 /// <param name="hasEverBeenUnlawfulDetainer">Initial value of the HasEverBeenUnlawfulDetainer property.</param>
 public static UserApplication CreateUserApplication(global::System.Int32 userId, global::System.Boolean hasBeenConvicted, global::System.Boolean hasEverBeenUnlawfulDetainer)
 {
     UserApplication userApplication = new UserApplication();
     userApplication.UserId = userId;
     userApplication.HasBeenConvicted = hasBeenConvicted;
     userApplication.HasEverBeenUnlawfulDetainer = hasEverBeenUnlawfulDetainer;
     return userApplication;
 }
예제 #4
0
        /// <summary>
        /// Gets the application for user. If the application doesn't
        /// exist then one is created.
        /// </summary>
        /// <param name="username">The username of the user.</param>
        /// <returns>
        /// A user application.
        /// </returns>
        public Status<UserApplication> GetApplicationForUser(string username)
        {
            using (var context = new RentlerContext())
            {
                // get the user
                User result = (from u in context.Users.Include("UserApplication")
                               where u.Username == username
                               select u).SingleOrDefault();

                if (result == null)
                    return Status.NotFound<UserApplication>();

                UserApplication application;

                if (result.UserApplication == null)
                {
                    application = new UserApplication();
                    application.UserId = result.UserId;
                    context.UserApplications.Add(application);
                    context.SaveChanges();
                }
                else
                {
                    application = result.UserApplication;
                }

                return Status.OK<UserApplication>(application);
            }
        }
예제 #5
0
 /// <summary>
 /// Deprecated Method for adding a new object to the UserApplications EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToUserApplications(UserApplication userApplication)
 {
     base.AddObject("UserApplications", userApplication);
 }