public IHttpActionResult StatusAccepted(string email)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest("Invalid data."));
            }
            IList <InstallmentRequestStatusViewModel> installmentRequest = null;
            // string currentUserId = User.Identity.GetUserId();
            LoanAndRepayEntities entities = new LoanAndRepayEntities();

            using (entities)
            {
                installmentRequest = (from installment in entities.InstallmentRequests
                                      where installment.Email == email && installment.Status == 1
                                      //where installment.Status == 1

                                      select new InstallmentRequestStatusViewModel()
                {
                    Company = installment.Company,
                    Status = "Accepted",
                }).ToList();
            }

            if (installmentRequest.Count == 0)
            {
                return(NotFound());
            }
            return(Ok(installmentRequest));
        }
示例#2
0
        public static void SaveInstallmentRequest(InstallmentRequestViewModel model, string UserId)
        {
            LoanAndRepayEntities entities           = new LoanAndRepayEntities();
            InstallmentRequest   installmentRequest = new InstallmentRequest();

            DAL.Address address = new DAL.Address();

            //First saves the installment request information in the installment table
            installmentRequest.UserId         = UserId;
            installmentRequest.Company        = model.Company;
            installmentRequest.FirstName      = model.FirstName;
            installmentRequest.LastName       = model.LastName;
            installmentRequest.Email          = model.Email;
            installmentRequest.Age            = model.Age;
            installmentRequest.Phone          = model.Phone;
            installmentRequest.Amount         = model.Amount;
            installmentRequest.PayWithIn      = model.PayWithIn;
            installmentRequest.MonthlyPayment = model.MonthlyPayment;
            installmentRequest.Status         = model.Status;
            entities.InstallmentRequests.Add(installmentRequest);
            entities.SaveChanges();
            var checkExistingInstallment = entities.InstallmentRequests.Where(x => x.Company == model.Company && x.Email == model.Email).FirstOrDefault();

            //Then saves the installment request address in the address table
            address.StreetName  = model.StreetName;
            address.HouseNumber = model.HouseNumber;
            address.CityName    = model.CityName;
            address.PostCode    = model.PostCode;

            address.InstallmentId = checkExistingInstallment.Id;
            entities.Addresses.Add(address);
            entities.SaveChanges();
        }
        public IHttpActionResult CompanyName()
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest("Invalid data."));
            }

            IList <CompanyNames> companyList = null;
            //string currentUserId = User.Identity.GetUserId();
            LoanAndRepayEntities entities = new LoanAndRepayEntities();


            using (entities)
            {
                companyList = (from companyInfo in entities.CompanyInfoes

                               select new CompanyNames()
                {
                    Name = companyInfo.CompanyName
                }).OrderBy(x => x.Name).ToList();
            }
            if (companyList.Count == 0)
            {
                return(NotFound());
            }
            return(Ok(companyList));
        }
        public IHttpActionResult InstallmentRequestStatusUpdate(int id, int status)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest("Invalid data."));
            }

            string currentUserId          = User.Identity.GetUserId();
            LoanAndRepayEntities entities = new LoanAndRepayEntities();


            using (entities)
            {
                var req = entities.InstallmentRequests.Where(x => x.Id == id).SingleOrDefault();

                if (status == 1 && req != null)
                {
                    req.Status = status;
                    entities.SaveChanges();
                }
                else if (status == 2 && req != null)
                {
                    req.Status = status;
                    entities.SaveChanges();
                }
            }

            return(Ok());
        }
示例#5
0
        public async Task <IHttpActionResult> RegisterCompany(RegisterCompanyBindingModel model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            using (LoanAndRepayEntities entities = new LoanAndRepayEntities())
            {
                var companyName = entities.CompanyInfoes.FirstOrDefault(x => x.CompanyName == model.CompanyName);
                if (companyName == null)
                {
                    var user = new ApplicationUser()
                    {
                        UserName = model.Email, Email = model.Email
                    };

                    IdentityResult result = await UserManager.CreateAsync(user, model.Password);

                    if (result.Succeeded)
                    {
                        var UserId = UserManager.FindByEmail(model.Email);
                        //Calling provider to save data
                        CompanyProvider.SaveCompanyInfo(model, UserId.Id);
                        UserManager.AddToRole(UserId.Id, "Company");
                    }
                    if (!result.Succeeded)
                    {
                        return(GetErrorResult(result));
                    }

                    return(Ok());
                }
            }
            return(BadRequest("Company name is already taken"));
        }
示例#6
0
        public static void SaveCompanyInfo(RegisterCompanyBindingModel registerCompanyModel, string userId)
        {
            LoanAndRepayEntities database = new LoanAndRepayEntities();

            CompanyInfo companyInfo = new CompanyInfo();

            DAL.Address address = new DAL.Address();
            if (companyInfo != null)
            {
                //First saves the company information in the company table
                companyInfo.UserId      = userId;
                companyInfo.CompanyName = registerCompanyModel.CompanyName;
                companyInfo.CVR         = registerCompanyModel.CVR;
                companyInfo.Email       = registerCompanyModel.Email;
                companyInfo.Phone       = registerCompanyModel.Phone;
                database.CompanyInfoes.Add(companyInfo);

                //Then saves the company address in the address table
                address.StreetName  = registerCompanyModel.StreetName;
                address.HouseNumber = registerCompanyModel.HouseNumber;
                address.CityName    = registerCompanyModel.CityName;
                address.PostCode    = registerCompanyModel.PostCode;
                address.UserId      = userId;
                database.Addresses.Add(address);
                database.SaveChanges();
            }
        }
示例#7
0
        public async Task <HttpResponseMessage> LoginUser(LoginUserBindingModel model)
        {
            // Invoke the "token" OWIN service to perform the login: /api/token
            // Ugly hack: I use a server-side HTTP POST because I cannot directly invoke the service (it is deeply hidden in the OAuthAuthorizationServerHandler class)
            var request = HttpContext.Current.Request;
            //To use locally
            //var tokenServiceUrl = "http://127.0.0.1:61902/Token";
            var tokenServiceUrl = request.Url.GetLeftPart(UriPartial.Authority) + request.ApplicationPath + "/Token";


            using (var client = new HttpClient())
            {
                var requestParams = new List <KeyValuePair <string, string> >
                {
                    new KeyValuePair <string, string>("grant_type", "password"),
                    new KeyValuePair <string, string>("username", model.Username),
                    new KeyValuePair <string, string>("password", model.Password)
                };
                var requestParamsFormUrlEncoded = new FormUrlEncodedContent(requestParams);
                var tokenServiceResponse        = await client.PostAsync(tokenServiceUrl, requestParamsFormUrlEncoded);

                var responseString = await tokenServiceResponse.Content.ReadAsStringAsync();

                var responseCode = tokenServiceResponse.StatusCode;
                var responseMsg  = new HttpResponseMessage(responseCode)
                {
                    Content = new StringContent(responseString, Encoding.UTF8, "application/json")
                };
                if (responseCode == HttpStatusCode.OK)
                {
                    LoanAndRepayEntities database = new LoanAndRepayEntities();

                    var Bodyresponse = database.AspNetUsers.FirstOrDefault(X => X.Email == model.Username);

                    // Get the roles associated with that user
                    var userRoles = await UserManager.GetRolesAsync(Bodyresponse.Id.ToString());

                    // Setup a RoleViewModel list of roles and iterate through userRoles adding them to the list
                    List <UserRoleViewModel> roleList = new List <UserRoleViewModel>();
                    foreach (var role in userRoles)
                    {
                        var item = new UserRoleViewModel {
                            Role = role
                        };
                        roleList.Add(item);
                        //return Ok(item);
                        var res = responseMsg;
                    }
                }
                return(responseMsg);
            }
        }
示例#8
0
        public static void CreateUser(RegisterBindingModel registerBindingModel)
        {
            LoanAndRepayEntities entities = new LoanAndRepayEntities();
            AspNetUser           user     = entities.AspNetUsers.SingleOrDefault(x => x.Email == registerBindingModel.Email);

            if (user != null)
            {
                user.FirstName   = registerBindingModel.FirstName;
                user.LastName    = registerBindingModel.LastName;
                user.PhoneNumber = registerBindingModel.PhoneNumber;
                user.Email       = registerBindingModel.Email;

                entities.SaveChanges();
            }
        }
        public IHttpActionResult SearchRequestByName(string name, string email)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest("Invalid data."));
            }

            IList <InstallmentRequestViewModel> installmentRequest = null;
            //string currentUserId = User.Identity.GetUserId();
            LoanAndRepayEntities entities = new LoanAndRepayEntities();

            using (entities)
            {
                installmentRequest = (from companyInfo in entities.CompanyInfoes
                                      join companyInfoJoin in entities.InstallmentRequests on companyInfo.CompanyName equals companyInfoJoin.Company
                                      join clientAddressJoin in entities.Addresses on companyInfoJoin.Id equals clientAddressJoin.InstallmentId

                                      where companyInfo.Email == email

                                      select new InstallmentRequestViewModel()
                {
                    Id = companyInfoJoin.Id,
                    Company = companyInfoJoin.Company,
                    FirstName = companyInfoJoin.FirstName,
                    LastName = companyInfoJoin.LastName,
                    Email = companyInfoJoin.Email,
                    Age = companyInfoJoin.Age,
                    Phone = companyInfoJoin.Phone,
                    StreetName = clientAddressJoin.StreetName,
                    HouseNumber = clientAddressJoin.HouseNumber,
                    CityName = clientAddressJoin.CityName,
                    PostCode = clientAddressJoin.PostCode,
                    Amount = companyInfoJoin.Amount,
                    PayWithIn = companyInfoJoin.PayWithIn,
                    MonthlyPayment = companyInfoJoin.MonthlyPayment,
                    Status = companyInfoJoin.Status
                }).Distinct().ToList();
            }
            if (!string.IsNullOrEmpty(name))
            {
                installmentRequest = installmentRequest.Where(x => x.FirstName.ToLower().Equals(name.Trim().ToLower())).ToList();
            }
            return(Ok(installmentRequest));
        }
        public static string SendEmailToCompany(InstallmentRequestViewModel model)
        {
            LoanAndRepayEntities entities = new LoanAndRepayEntities();
            var findEmail = entities.CompanyInfoes.Where(x => x.CompanyName == model.Company).FirstOrDefault();

            try
            {
                SmtpClient SmtpServer = new SmtpClient("smtp.live.com");
                var        mail       = new System.Net.Mail.MailMessage();
                mail.From = new MailAddress("*****@*****.**");
                mail.To.Add(findEmail.Email);
                mail.Subject    = "Installment request for " + model.Company;
                mail.IsBodyHtml = true;
                string htmlBody;

                htmlBody = "Hi " + model.Company + "," + "<br />" + "<br />"
                           + "The following person requests for an installement:" + "<br />" + "<br />"
                           + "First Name = " + model.FirstName + "<br />"
                           + "Last Name = " + model.LastName + "<br />"
                           + "Email = " + model.Email + "<br />"
                           + "Age = " + model.Age + "<br />"
                           + "Phone = " + model.Phone + "<br />"
                           + "Street Name = " + model.StreetName + "<br />"
                           + "House Number = " + model.HouseNumber + "<br />"
                           + "City Name = " + model.CityName + "<br />"
                           + "Post Code = " + model.PostCode + "<br />"
                           + "Amount = " + model.Amount + "<br />"
                           + "Pay within = " + model.PayWithIn + "<br />" + "<br />"
                           + "Regards," + "<br />"
                           + "SteamFoss" + ".";
                mail.Body       = htmlBody;
                SmtpServer.Port = 587;
                SmtpServer.UseDefaultCredentials = false;
                SmtpServer.Credentials           = new NetworkCredential("*****@*****.**", "m42929264.", "Outlook.com");
                SmtpServer.EnableSsl             = true;
                SmtpServer.Send(mail);

                return("sent");
            }
            catch (Exception ex)
            {
                return(ex.Message);
            }
        }