Пример #1
0
        public static bool CustomerCardRequestExists(string serialNumber)
        {
            try
            {
                var existingCardRequest = new CardRequest();
                using (var context = new KioskWebDBEntities())
                {
                    existingCardRequest = context.CardRequests
                                    .Where(t => t.SerialNumber.Equals(serialNumber))
                                    .FirstOrDefault();
                }

                if (existingCardRequest == null)
                    return false;
                else
                    return true;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Пример #2
0
 public static bool UpdateCardRequest(long cardRequestID, string requestType, string loggedInUsername)
 {
     try
     {
         string clearPan = string.Empty;
         CardRequest cardRequest = new CardRequest();
         if (requestType == StatusUtil.RequestType.WithSerialNumber.ToString())
         {
             List<KioskSolutionLibrary.ModelLibrary.EntityFrameworkLibrary.ThirdPartyData.PANDetail> unusedPans = ThirdPartyDL.RetrieveUnUsedPanDetails();
             if (unusedPans.Count == 0)
             {
                 throw new Exception("There are no available pans for linking");
             }
             else
             {
                 clearPan = unusedPans.Take(1).First().pan;
             }
         }
         bool updated = CustomerDL.UpdateCardRequest(cardRequestID, clearPan, loggedInUsername, out cardRequest);
         if(updated)
         {
             Mail.SendCardPickup(cardRequest);
         }
         return updated;
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Пример #3
0
        public static bool SaveCardRequest(CardRequest cardRequest, string username)
        {
            try
            {
                CardRequest savedCardRequest = new CardRequest();

                bool saved = CustomerDL.SaveCardRequest(cardRequest, username, out savedCardRequest);
                if (saved)
                {
                    Mail.SendCardPickup(savedCardRequest);
                }
                return saved;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Пример #4
0
        public static bool UpdateCardRequest(long cardRequestID, string clearPan, string loggedInUsername, out CardRequest cardRequest)
        {
            try
            {
                CardRequest existingRequest = new CardRequest();
                using (var context = new KioskWebDBEntities())
                {
                    existingRequest = context.CardRequests
                                    .Include(cr => cr.Customer)
                                    .Include(cr => cr.Branch)
                                    .Where(t => t.ID == cardRequestID)
                                    .FirstOrDefault();
                }

                if (existingRequest != null)
                {
                    if (existingRequest.RequestType == StatusUtil.RequestType.WithSerialNumber.ToString())
                    {
                        existingRequest.HashedPan = PasswordHash.MD5Hash(clearPan);
                        existingRequest.EncryptedPan = Crypter.Encrypt(System.Configuration.ConfigurationManager.AppSettings.Get("ekey"), clearPan);
                    }
                    existingRequest.Status = StatusUtil.CardStatus.Approved.ToString();

                    using (var context = new KioskWebDBEntities())
                    {
                        using (var transaction = context.Database.BeginTransaction())
                        {
                            context.Entry(existingRequest).State = EntityState.Modified;
                            context.SaveChanges();

                            KioskSolutionLibrary.ModelLibrary.EntityFrameworkLibrary.ThirdPartyData.User thirdPartyUser = ThirdPartyDL.RetrieveUserByUsername(loggedInUsername);

                            KioskSolutionLibrary.ModelLibrary.EntityFrameworkLibrary.ThirdPartyData.CardAccountRequest car = new ModelLibrary.EntityFrameworkLibrary.ThirdPartyData.CardAccountRequest();

                            car.NameOnCard = string.Format("{0} {1}", existingRequest.Customer.Lastname, existingRequest.Customer.Othernames);
                            if (existingRequest.RequestType == StatusUtil.RequestType.WithSerialNumber.ToString())
                                car.PAN = clearPan;
                            car.PrintStatus = 1;
                            car.UserPrinting = thirdPartyUser.id.ToString();
                            car.DATE = System.DateTime.Now;
                            if (existingRequest.RequestType == StatusUtil.RequestType.WithSerialNumber.ToString())
                                car.HolderIDNumber = existingRequest.SerialNumber;
                            car.PhoneNumber = existingRequest.Customer.PhoneNumber;
                            car.LastName = existingRequest.Customer.Lastname;
                            car.OtherName = existingRequest.Customer.Othernames;
                            car.emailaddress = existingRequest.Customer.EmailAddress;
                            car.Updateddate = System.DateTime.Now;
                            ThirdPartyDL.SaveCar(car);

                            ThirdPartyDL.UpdatePan(clearPan);

                            transaction.Commit();
                        }
                    }
                    cardRequest = existingRequest;
                    return true;
                }
                else
                {
                    cardRequest = null;
                    return false;
                }

            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Пример #5
0
        public static bool SaveCardRequest(CardRequest cardRequest, string loggedInUsername, out CardRequest savedCardRequest)
        {
            try
            {
                using (var context = new KioskWebDBEntities())
                {
                    using (var transaction = context.Database.BeginTransaction())
                    {
                        context.CardRequests.Add(cardRequest);
                        context.SaveChanges();

                        KioskSolutionLibrary.ModelLibrary.EntityFrameworkLibrary.ThirdPartyData.User thirdPartyUser = ThirdPartyDL.RetrieveUserByUsername(loggedInUsername);

                        Customer cardRequestCustomer = RetrieveCustomerByID(cardRequest.CustomerID);

                        KioskSolutionLibrary.ModelLibrary.EntityFrameworkLibrary.ThirdPartyData.CardAccountRequest car = new ModelLibrary.EntityFrameworkLibrary.ThirdPartyData.CardAccountRequest();

                        car.NameOnCard = string.Format("{0} {1}", cardRequestCustomer.Lastname, cardRequestCustomer.Othernames);

                        if (cardRequest.RequestType == StatusUtil.RequestType.WithSerialNumber.ToString())
                        {
                            KioskSolutionLibrary.ModelLibrary.EntityFrameworkLibrary.ThirdPartyData.PANDetail panDetail = ThirdPartyDL.RetrievePanDetailByAccountNumber(cardRequest.SerialNumber);

                            car.PAN = panDetail.pan;

                            ThirdPartyDL.UpdatePan(panDetail.pan);
                        }

                        car.PrintStatus = 1;
                        car.UserPrinting = thirdPartyUser.id.ToString();
                        car.DATE = System.DateTime.Now;
                        if (cardRequest.RequestType == StatusUtil.RequestType.WithSerialNumber.ToString())
                            car.HolderIDNumber = cardRequest.SerialNumber;
                        car.PhoneNumber = cardRequestCustomer.PhoneNumber;
                        car.LastName = cardRequestCustomer.Lastname;
                        car.OtherName = cardRequestCustomer.Othernames;
                        car.emailaddress = cardRequestCustomer.EmailAddress;
                        car.Updateddate = System.DateTime.Now;
                        ThirdPartyDL.SaveCar(car);

                        cardRequest.Customer = cardRequestCustomer;

                        transaction.Commit();
                    }
                }
                cardRequest.Branch = BranchDL.RetrieveBranchByID(cardRequest.PickupBranchID);
                savedCardRequest = cardRequest;
                return true;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Пример #6
0
        public HttpResponseMessage SaveCustomerCardRequest([FromBody]CardRequestModel cardRequestModel)
        {
            try
            {
                CardRequest cardRequest = new CardRequest();
                cardRequest.CustomerID = cardRequestModel.CustomerID;
                cardRequest.CardType = Enum.GetName(typeof(StatusUtil.CardType), cardRequestModel.CardTypeID);
                cardRequest.RequestType = Enum.GetName(typeof(StatusUtil.RequestType), cardRequestModel.RequestTypeID);
                cardRequest.PickupBranchID = cardRequestModel.PickupBranchID;
                cardRequest.Status = StatusUtil.CardStatus.Approved.ToString();
                cardRequest.ModifiedDate = System.DateTime.Now;
                cardRequest.SerialNumber = cardRequestModel.SerialNumber;

                string username = cardRequestModel.Username;

                bool result = CustomerPL.SaveCardRequest(cardRequest, username);

                return result.Equals(true) ? Request.CreateResponse(HttpStatusCode.OK, "Successful") : Request.CreateResponse(HttpStatusCode.BadRequest, "Request failed");
            }
            catch (Exception ex)
            {
                ErrorHandler.WriteError(ex);
                var response = Request.CreateResponse(HttpStatusCode.BadRequest, ex.Message);
                return response;
            }
        }
Пример #7
0
        public static void SendCardPickup(CardRequest cardRequest)
        {
            try
            {

                string userFullName = cardRequest.Customer.Lastname + " " + cardRequest.Customer.Othernames;
                string organization = System.Configuration.ConfigurationManager.AppSettings.Get("Organization");
                string applicationName = System.Configuration.ConfigurationManager.AppSettings.Get("ApplicationName");
                string subject = "Welcome to " + applicationName;
                string fromAddress = "";
                string smtpUsername = "";
                string smtpPassword = "";
                string smtpHost = "";
                Int32 smtpPort = 587;
                bool smtpUseDefaultCredentials = false;
                bool smtpEnableSsl = true;

                MailHelper mailConfig = ConfigurationManager.GetSection("mailHelperSection") as MailHelper;
                if (mailConfig != null && mailConfig.Mail != null)
                {
                    fromAddress = mailConfig.Mail.FromEmailAddress;
                    smtpUsername = mailConfig.Mail.Username;
                    smtpPassword = mailConfig.Mail.Password;
                }

                if (mailConfig != null && mailConfig.Smtp != null)
                {
                    smtpHost = mailConfig.Smtp.Host;
                    smtpPort = Convert.ToInt32(mailConfig.Smtp.Port);
                    smtpUseDefaultCredentials = Convert.ToBoolean(mailConfig.Smtp.UseDefaultCredentials);
                    smtpEnableSsl = Convert.ToBoolean(mailConfig.Smtp.EnableSsl);
                }

                string body = "";

                if (cardRequest.RequestType == StatusUtil.RequestType.WithoutSerialNumber.ToString())
                    body = System.IO.File.ReadAllText(System.Web.Hosting.HostingEnvironment.MapPath(@"~/App_Data/MailTemplates/CardPickUp.txt"));
                else
                {
                    body = System.IO.File.ReadAllText(System.Web.Hosting.HostingEnvironment.MapPath(@"~/App_Data/MailTemplates/CardPickUpSerialNumber.txt"));
                    body = body.Replace("#SerialNumber", cardRequest.SerialNumber);
                }
                body = body.Replace("#Organization", organization);
                body = body.Replace("#ApplicationName", applicationName);
                body = body.Replace("#UserFullName", userFullName);
                body = body.Replace("#PickUpBranch", cardRequest.Branch.Name);

                Thread email = new Thread(delegate()
                {
                    Mail.SendMail(cardRequest.Customer.EmailAddress, fromAddress, subject, body, smtpHost, smtpPort, smtpUseDefaultCredentials, smtpUsername, smtpPassword, smtpEnableSsl);

                });

                email.IsBackground = true;
                email.Start();

            }
            catch (Exception ex)
            {
                ErrorHandler.WriteError(ex);
                throw ex;
            }
        }