Esempio n. 1
0
        private void setTextbox()
        {
            if (!String.IsNullOrEmpty(tbIdcustomer.Text))
            {
                cust = db.tbl_Customers.FirstOrDefault(x => x.id_customer == int.Parse(tbIdcustomer.Text));
                if (cust != null)
                {
                    tbNamecustomer.Text        = cust.name_customer;
                    rtbAddresscustomer.Text    = cust.address_customer;
                    tbEmailcustomer.Text       = cust.email_customer;
                    tbPhonenumbercustomer.Text = cust.phonenumber_customer;
                    btnAdd.Text = "UPDATE";
                }

                else
                {
                    va.clear("tbIdcustomer", 0);
                    btnAdd.Text = "ADD";
                }
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Save Data To Database
        /// <para>Use it when save data through a stored procedure</para>
        /// </summary>
        public int SaveCustomer(tbl_Customer model)
        {
            int result = 0;

            try
            {
                Hashtable ht = new Hashtable();
                ht.Add("Name", model.Name);
                ht.Add("Email", model.Email);
                ht.Add("Mobile", model.Mobile);

                string spQuery = "[Set_Customer]";
                result = GenericFactoryFor_Customer.ExecuteCommand(spQuery, ht);
            }
            catch (Exception e)
            {
                e.ToString();
            }

            return(result);
        }
        public Customer CheckCustomerLogin(string name, string password)
        {
            Customer obj_customer = new Customer();

            using (OnlineShoppingDataContext db = new OnlineShoppingDataContext())
            {
                tbl_Customer cus = (from a in db.tbl_Customers where a.CustomerName == name && a.CustomerPassword == password select a).FirstOrDefault();

                if (cus != null)
                {
                    obj_customer.CustomerID       = cus.CustomerID;
                    obj_customer.CustomerName     = cus.CustomerName;
                    obj_customer.CustomerEmail    = cus.CustomerEmail;
                    obj_customer.CustomerMobile   = cus.CustomerMobile;
                    obj_customer.CustomerAddress  = cus.CustomerAddress;
                    obj_customer.CustomerPassword = cus.CustomerPassword;
                    obj_customer.IsAdmin          = Convert.ToBoolean(cus.IsAdmin);
                }
            }
            return(obj_customer);
        }
    private bool CreateNewUser()
    {
        tbl_Customer Customer = new tbl_Customer();

        try
        {
            HarperMembershipService.GetMemberResponse user = (HarperMembershipService.GetMemberResponse)Session["MemberResponse"];
            object[] response = tbl_Customer.CreateCustomer(user.MemberData.Address.Address1,
                                                            user.MemberData.Address.Address2,
                                                            user.MemberData.Address.Address3,
                                                            user.MemberData.Address.City,
                                                            user.MemberData.Address.State,
                                                            user.MemberData.Address.Country,
                                                            user.MemberData.Address.PostalCode,
                                                            null,
                                                            txtPassword.Text.Trim(), "UNKNOWN",
                                                            user.MemberData.Salutation,
                                                            user.MemberData.FirstName,
                                                            user.MemberData.MiddleInitial,
                                                            user.MemberData.LastName,
                                                            user.MemberData.Suffix,
                                                            user.MemberData.Email,
                                                            txtUserName.Text.Trim(),
                                                            CustomerID,
                                                            user.MemberData.Subscriptions[0].PublicationCode,
                                                            user.MemberData.Subscriptions[0].ExpireDate,
                                                            user.MemberData.Subscriptions[0].DateEntered,
                                                            txtUserName.Text.Trim(),
                                                            string.Empty);
            if (response != null && response[0] != null && ((int)response[0]) == 0 && response[1] != null)
            {
                Customer = (tbl_Customer)response[1];
            }
        }
        catch
        {
            return(false);
        }
        return(true);
    }
        //GET: Order
        public ActionResult Ordering()
        {
            CartData cart = (CartData)Session["cart"];

            if (cart.amounts == 0)
            {
                return(Redirect(Request.UrlReferrer.AbsoluteUri));
            }
            String       cus_address = Request.Form.Get("address");
            String       cus_name    = Request.Form.Get("name");
            tbl_Customer cus         = (tbl_Customer)Session["user"];
            CartData     cartList    = (CartData)Session["cart"];
            tbl_Bill     bill        = db.tbl_Bill.Create();

            bill.cus_id       = cus.id;
            bill.level_status = 0;
            bill.total_price  = cartList.cost;
            bill.cus_address  = cus_address;
            bill.cus_name     = cus_name;
            bill.created_at   = DateTime.Now;
            db.tbl_Bill.Add(bill);
            for (int i = 0; i < cartList.arrCart.Count; i++)
            {
                Cart           c          = (Cart)cartList.arrCart[i];
                tbl_BillDetail billDetail = db.tbl_BillDetail.Create();
                billDetail.bill_id = bill.id;
                billDetail.pro_id  = c.item.id;
                billDetail.price   = c.cost * c.amounts;
                billDetail.amount  = c.amounts;
                db.tbl_BillDetail.Add(billDetail);
                tbl_Product p = db.tbl_Product.Find(c.item.id);
                p.amount         -= c.amounts;
                db.Entry(p).State = System.Data.Entity.EntityState.Modified;
            }
            db.SaveChanges();
            Session.Remove("cart");
            return(RedirectToAction("Account"));
        }
Esempio n. 6
0
        public HttpResponseMessage CustomerLogin(tbl_Customer customer)
        {
            proc_LoginCheck_Result rslt = null;
            tbl_Customer           cust = null;

            try
            {
                rslt = entities.proc_LoginCheck(customer.Username, customer.Passwords).FirstOrDefault();
                if (rslt != null)
                {
                    cust = entities.tbl_Customer.Where(c => c.Customer_Id == rslt.Customer_id).FirstOrDefault();
                    return(Request.CreateResponse(HttpStatusCode.OK, cust));
                }
                else
                {
                    return(Request.CreateErrorResponse(HttpStatusCode.NotFound, "Invalid Login"));
                }
            }
            catch (Exception)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Invalid login"));
            }
        }
Esempio n. 7
0
 public CustomerViewModel(tbl_Customer customer, int?stageID)
 {
     CusId          = customer.CusId;
     CusCMND        = customer.CusCMND;
     CusName        = customer.CusName;
     CusPhone       = customer.CusPhone;
     CusAddress     = customer.CusAddress;
     CusCompany     = customer.CusCompany;
     CusPosition    = customer.CusPosition;
     CusSalary      = customer?.CusSalary;
     CusNote        = customer.CusNote;
     CusEmail       = customer.CusEmail;
     CusSexIsMale   = customer?.CusSexIsMale;
     CusDateOfBirth = customer?.CusDateOfBirth;
     CusCICNumber   = customer.CusCICNumber;
     CusLimitOffer  = customer?.CusLimitOffer;
     CusDistrict    = customer.CusDistrict;
     CusCity        = customer.CusCity;
     CusLeadProDuct = customer.CusLeadProDuct;
     CusVPID        = customer.CusVPID;
     Branches       = customer.Branches;
     stageId        = stageID;
 }
Esempio n. 8
0
        private void btnAdd_Click(object sender, EventArgs e)
        {
            try
            {
                String       message = "";
                DialogResult fc      = MessageBox.Show("Are you sure want to add this data?", Application.ProductName, MessageBoxButtons.YesNo, MessageBoxIcon.Information);
                if (fc == DialogResult.No)
                {
                    return;
                }
                if (va.doValidation() == false)
                {
                    return;
                }
                cust = db.tbl_Customers.FirstOrDefault(i => i.id_customer == int.Parse(tbIdCustomer.Text));
                if (cust != null)
                {
                    message = "Update";
                    action("update");
                }

                else
                {
                    message = "Insert";
                    action("insert");
                }

                MessageBox.Show(message + " data success!", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Information);
                loadGrid();
                va.clear("");
            }

            catch (Exception err)
            {
                MessageBox.Show(err.ToString());
            }
        }
Esempio n. 9
0
        public List <ProductsView> GetSavingsAccounts(Guid id)
        {
            if (string.IsNullOrWhiteSpace(id.ToString()))
            {
                return(new List <ProductsView>());
            }

            tbl_Customer customer = customerAccountsManager.CustomerDetails(id);

            List <tbl_CustomerAccounts> accounts     = customerAccountsManager.GetCustomerSavingsAccounts(customer.CustomerNo);
            List <tbl_accounttypes>     accountTypes = customerAccountsManager.GetAccountTypes();

            List <ProductsView> savingsAccounts = (from account in accounts
                                                   join types in accountTypes on account.AccountType equals types.code
                                                   select new ProductsView
            {
                ProductCode = (types.act_code ?? string.Empty).Trim(),
                ProductName = (types.category ?? string.Empty).Trim(),
                AccountNo = (account.AccountNo ?? string.Empty).Trim(),
                Balance = 0,
            }).ToList();

            return(savingsAccounts);
        }
Esempio n. 10
0
    protected void btnSumbit_click(object sender, EventArgs e)
    {
        try
        {
            #region Unable to decode referral id, try finding original referral based on email address
            if (badReferralId)
            {
                try
                {
                    Referral badRef = new Referral(email_address.Text);
                    if (badRef.id > 0)
                    {
                        referralid = badRef.id;
                    }
                    else
                    {
                        throw new Exception();
                    }
                }
                catch (Exception ex)
                {
                    logService.LogAppEvent("", @"HarperNET", "Referral", "Unable to link email to referral id (id could not be decoded and email not on file). Using default referrer. Referral id in url: " + Request["ReferralId"] + ", email address entered: " + email_address.Text, ex.Message, ex.StackTrace, "", "Page_Load");

                    Referral defaultReferral = new Referral();
                    defaultReferral.keycode = "POTRIAL";
                    defaultReferral.pubcode = "PO";
                    ReferralOffer offer = new ReferralOffer(defaultReferral.keycode, defaultReferral.pubcode);

                    defaultReferral.ccmember    = false;
                    defaultReferral.datecreated = DateTime.Now;
                    defaultReferral.dateexpires = defaultReferral.datecreated.AddMonths(offer.offerexpiresmonths);
                    defaultReferral.friendemail = email_address.Text;
                    defaultReferral.friendname  = first_name.Text + " " + last_name.Text;

                    HarperLINQ.tbl_Customer defaultReferrer = new tbl_Customer(ConfigurationManager.AppSettings["default_referrer_username"], true);
                    defaultReferral.memberid           = defaultReferrer.cusID;
                    defaultReferral.subscriptionlength = offer.triallengthinmonths;

                    defaultReferral.Save();
                    referralid = defaultReferral.id;
                }
            }
            #endregion

            HarperMembershipService.BaseResponse      response   = new HarperMembershipService.BaseResponse();
            HarperMembershipService.MembershipService webservice = new HarperMembershipService.MembershipService();

            #region Get selected region
            country = ddlCountries.SelectedValue;
            ISO3166 iso            = new ISO3166(country, IdentifierType.Country_Code_Alpha2);
            string  sfgcountrycode = iso.SFGCode;

            if (txtRegion.Text != "" && txtRegion.Text != null)
            {
                region = txtRegion.Text;
            }
            else if (txtRegionNotListed.Text != "" && txtRegionNotListed.Text != null)
            {
                region = txtRegionNotListed.Text;
            }
            else
            {
                region = ddlRegion.SelectedValue;
            }
            #endregion

            string erefid = Cryptography.EncryptData(referralid.ToString());
            string epwd   = Cryptography.EncryptData(txtPassword.Text);

            #region Redeem the referral
            response = webservice.RedeemReferral(erefid, first_name.Text, last_name.Text, email_address.Text,
                                                 sfgcountrycode, address_line_1.Text, address_line_2.Text, city.Text, region, postal.Text, true,
                                                 txtUserName.Text, epwd);
            #endregion

            #region Check for errors
            if (response == null)
            {
                throw new Exception(string.Format("Error redeeming referral id {0}, response from SFG was null.", referralid));
            }
            if (response.Messages != null && response.Messages.Count() > 0)
            {
                throw new Exception(response.Messages[0].AhMessage);
            }
            #endregion

            Response.Redirect("~/Referral/RedemptionConfirmation.aspx", false);
        }
        catch (Exception ex)
        {
            logService.LogAppEvent("", @"HarperNET", "Referral", "Error in btnSumbit_click", ex.Message, ex.StackTrace, "", "btnSubmit_click");
            LiteralControl err = new LiteralControl();
            err.Text = "<p class=\"error-message\">An error has occurred.  Please contact the membership department at <a href=\"mailto:[email protected]\">[email protected]</a></p>";
            lblErrorMessage.Controls.Add(err);
            lblErrorMessage.Visible = true;
        }
    }
Esempio n. 11
0
 public tbl_Customer Insert(tbl_Customer Customer)
 {
     throw new NotImplementedException();
 }
Esempio n. 12
0
 public bool registration(tbl_Customer customer)
 {
     customerRegistration.tbl_Customer.AddObject(customer);
     return(customerRegistration.SaveChanges() > 0);
 }
Esempio n. 13
0
        public static string Insert(string CustomerName, string CustomerPhone, string CustomerAddress, string CustomerEmail, int CustomerLevelID, int Status,
                                    DateTime CreatedDate, string CreatedBy, bool IsHidden, string Zalo, string Facebook, string Note, string Province, string Nick, string Avatar = "", int ShippingType = 0, int PaymentType = 0, int TransportCompanyID = 0, int TransportCompanySubID = 0, string CustomerPhone2 = "")
        {
            using (var dbe = new inventorymanagementEntities())
            {
                tbl_Customer ui = new tbl_Customer();
                ui.CustomerName    = CustomerName;
                ui.CustomerPhone   = CustomerPhone;
                ui.CustomerAddress = CustomerAddress;
                if (!string.IsNullOrEmpty(CustomerEmail))
                {
                    ui.CustomerEmail = CustomerEmail;
                }
                ui.CustomerLevelID = CustomerLevelID;
                ui.Status          = Status;
                ui.CreatedDate     = CreatedDate;
                ui.CreatedBy       = CreatedBy;
                ui.IsHidden        = IsHidden;

                if (!string.IsNullOrEmpty(Zalo))
                {
                    ui.Zalo = Zalo;
                }
                if (!string.IsNullOrEmpty(Facebook))
                {
                    ui.Facebook = Facebook;
                }
                if (!string.IsNullOrEmpty(Note))
                {
                    ui.Note = Note;
                }
                if (!string.IsNullOrEmpty(Province))
                {
                    ui.ProvinceID = Province.ToInt();
                }

                ui.Nick = Nick;

                if (!string.IsNullOrEmpty(Avatar))
                {
                    ui.Avatar = Avatar;
                }

                ui.ShippingType          = ShippingType;
                ui.PaymentType           = PaymentType;
                ui.TransportCompanyID    = TransportCompanyID;
                ui.TransportCompanySubID = TransportCompanySubID;
                ui.CustomerPhone2        = CustomerPhone2;
                try
                {
                    dbe.tbl_Customer.Add(ui);
                    dbe.SaveChanges();
                }
                catch (DbEntityValidationException dbEx)
                {
                    foreach (var validationErrors in dbEx.EntityValidationErrors)
                    {
                        foreach (var validationError in validationErrors.ValidationErrors)
                        {
                            System.Console.WriteLine("Property: {0} Error: {1}", validationError.PropertyName, validationError.ErrorMessage);
                        }
                    }
                }
                int kq = ui.ID;
                return(kq.ToString());
            }
        }
 public string GetCustomerName(tbl_Customer Customers)
 {
     return(GetCustomerName(Customers.CustomerName, Customers.CompanyName));
 }
Esempio n. 15
0
        public BaseResponse CreateReferral(string cusid, string membername, string memberemail, string keycode,
                                           string pubcode, string friendname, string friendemailaddress, bool ccmember)
        {
            methodName = "CreateReferral";

            List <Message> errors   = new List <Message>();
            Referral       referral = new Referral();

            try
            {
                tbl_Customer member = new tbl_Customer(int.Parse(cusid), false);

                #region validate input
                if (member == null)
                {
                    errors.Add(new Message(MessageSources.AndrewHarper, 0, "CreateReferralInputValidationException", BusinessLogicStrings.memberDoesNotExistError, cusid, "", null));
                }
                if (member.SfgId == null)
                {
                    errors.Add(new Message(MessageSources.AndrewHarper, 0, "CreateReferralInputValidationException", BusinessLogicStrings.invalidMemberIdError, "", "", null));
                }
                if (string.IsNullOrEmpty(membername))
                {
                    errors.Add(new Message(MessageSources.AndrewHarper, 0, "CreateReferralInputValidationException", BusinessLogicStrings.missingMemberNameError, "", "", null));
                }
                if (ccmember && string.IsNullOrEmpty(memberemail))
                {
                    errors.Add(new Message(MessageSources.AndrewHarper, 0, "CreateReferralInputValidationException", BusinessLogicStrings.missingMemberEmailError, "", "", null));
                }
                if (string.IsNullOrEmpty(keycode))
                {
                    errors.Add(new Message(MessageSources.AndrewHarper, 0, "CreateReferralInputValidationException", BusinessLogicStrings.missingKeycodeError, "", "", null));
                }
                if (string.IsNullOrEmpty(pubcode))
                {
                    errors.Add(new Message(MessageSources.AndrewHarper, 0, "CreateReferralInputValidationException", BusinessLogicStrings.missingPubcodeError, "", "", null));
                }
                if (string.IsNullOrEmpty(friendname))
                {
                    errors.Add(new Message(MessageSources.AndrewHarper, 0, "CreateReferralInputValidationException", BusinessLogicStrings.missingFriendNameError, "", "", null));
                }
                if (string.IsNullOrEmpty(friendemailaddress))
                {
                    errors.Add(new Message(MessageSources.AndrewHarper, 0, "CreateReferralInputValidationException", BusinessLogicStrings.missingFriendEmailError, "", "", null));
                }
                #endregion

                #region enforce business rules
                tbl_Customer friend = new tbl_Customer(friendemailaddress, false);
                try
                {
                    Referral existing_referral = new Referral(friendemailaddress);

                    if (memberemail == friendemailaddress)
                    {
                        errors.Add(new Message(MessageSources.AndrewHarper, 0, "CreateReferralBusinessRuleException", BusinessLogicStrings.cannotReferSelfError, "", "", null));
                    }
                    else if (friend.cusID > 0)
                    {
                        errors.Add(new Message(MessageSources.AndrewHarper, 0, "CreateReferralBusinessRuleException", BusinessLogicStrings.existingMemberError, "", "", null));
                    }
                    else if (existing_referral.dateredeemed == null)
                    {
                        if (existing_referral.id > 0 && existing_referral.dateexpires.CompareTo(DateTime.Now) >= 0)
                        {
                            errors.Add(new Message(MessageSources.AndrewHarper, 0, "CreateReferralBusinessRuleException", BusinessLogicStrings.existingReferralError, "", "", null));
                        }
                    }
                    if (errors.Count <= 0)
                    {
                        GetMemberResponse checkFriend = (GetMemberByUserName(friendemailaddress).TypedResponse as GetMemberResponse);
                        if (checkFriend != null && (checkFriend.MemberFound || checkFriend.WebAccountFound))
                        {
                            errors.Add(new Message(MessageSources.AndrewHarper, 0, "CreateReferralBusinessRuleException", BusinessLogicStrings.freindEmailInUseSFGError, "", "", null));
                        }
                    }
                }
                catch (HarperLINQ.DataLoadException dle)
                {
                    errors.Add(new Message(MessageSources.AndrewHarper, 0, "CreateReferralBusinessRuleException", BusinessLogicStrings.freindEmailInUseAHError, "", "", null));
                }
                if (errors.Count() > 0)
                {
                    string errstring = string.Empty;
                    foreach (Message msg in errors)
                    {
                        string sfgmessages = string.Empty;
                        if (msg.SfgMessages != null)
                        {
                            foreach (string sfgmsg in msg.SfgMessages)
                            {
                                sfgmessages += string.Format("SFGMessage: {0}", sfgmsg);
                            }
                        }
                        errstring += string.Format("AhMessage: {0}|| {1}", new object[] { msg.AhMessage, sfgmessages });
                    }
                    throw new Exception(string.Format("Error creating referral: [{0}]", errstring));
                }
                #endregion

                ReferralOffer offer = new ReferralOffer(keycode, pubcode);


                #region save referral
                referral = new Referral(int.Parse(cusid), membername, memberemail, keycode, pubcode, friendname, friendemailaddress, ccmember, offer.triallengthinmonths, offer.offerexpiresmonths);
                referral.Save();
                #endregion

                #region send email
                //create mailer and sent mail
                Mailer mailer = new Mailer();

                string ccEmail = memberemail;

                if (!ccmember)
                {
                    ccEmail = string.Empty;
                }

                mailer.SendEmail(ConfigurationManager.AppSettings["mailserviceuser"],
                                 ConfigurationManager.AppSettings["mailservicepwd"],
                                 string.Format("Membership Invitation from {0}", membername),
                                 ConfigurationManager.AppSettings["referemailfrom"],
                                 friendemailaddress,
                                 ccEmail,
                                 string.Empty,
                                 referral.GetReferralEmailBody(),
                                 true,
                                 ConfigurationManager.AppSettings["smtpserver"]);
                #endregion
            }
            catch (Exception ex)
            {
                LogMethodError(methodName, ex);
            }
            if (baseResponse != null && baseResponse.Messages != null)
            {
                foreach (Message error in errors)
                {
                    baseResponse.Messages.Add(error);
                }
            }
            if (baseResponse.Messages.Count() <= 0 && referral != null && referral.id >= 0)
            {
                #region create typed response
                baseResponse.TypedResponse         = new ReferralResponse();
                baseResponse.TypedResponse.Success = true;
                (baseResponse.TypedResponse as ReferralResponse).referralid = referral.id;
                #endregion
            }
            else
            {
                baseResponse.TypedResponse         = new ReferralResponse();
                baseResponse.TypedResponse.Success = false;
            }

            return(baseResponse);
        }
Esempio n. 16
0
 public void add(tbl_Customer item)
 {
     rep.add(item);
 }
Esempio n. 17
0
        /// Get Customers detail by Id
        public CustomerViewModel GetCustomerDetailById(long Id)
        {
            tbl_Customer customers = _Context.tbl_Customer.Where(x => x.Id == Id).FirstOrDefault();

            return(Mapper.Map(customers, new CustomerViewModel()));
        }
Esempio n. 18
0
        public tbl_SaleOrder InsertOrder(ExportRetailModel model)
        {
            try
            {
                using (var db = _connectionData.OpenDbConnection())
                {
                    var sysHotel = comm.GetHotelId();
                    #region Khách hàng

                    var sysCustomer = new tbl_Customer
                    {
                        Name           = model.CustomerName,
                        Phone          = model.CustomerPhone,
                        CreateDate     = DateTime.Now,
                        Mobile         = model.CustomerPhone,
                        SysHotelID     = sysHotel,
                        CreateBy       = comm.GetUserId(),
                        IdentifyNumber = model.CustomerPhone,
                        Status         = true
                    };
                    var customerId = (int)db.Insert(sysCustomer, selectIdentity: true);
                    #endregion
                    #region Insert đơn
                    var objInsert = new tbl_SaleOrder
                    {
                        CustomerID    = customerId,
                        SysHotelID    = sysHotel,
                        AmountNoTax   = model.TotalAmount,
                        Tax           = model.SurchargeAmount,
                        TotalAmount   = (model.TotalAmount - model.SurchargeAmount),
                        DateCreated   = DateTime.Now,
                        DatePayment   = DateTime.ParseExact(model.SPayTime, "dd/MM/yyyy hh:mm:ss", null),
                        PaymentTypeID = null,
                        TypeOrder     = 1,
                        CreatorID     = comm.GetUserId()
                    };
                    var iTblSaleOrderId = (int)db.Insert(objInsert, selectIdentity: true);
                    #endregion
                    #region Chi tiết đơn
                    if (model.ListRetailDetail != null)
                    {
                        foreach (var detail in model.ListRetailDetail)
                        {
                            var objDetail = new tbl_SaleOrderDetail
                            {
                                SysHotelID    = sysHotel,
                                OrderID       = iTblSaleOrderId,
                                catalogitem   = detail.ProductName,
                                item          = detail.ProductName,
                                itemid        = detail.ProductId,
                                catalogitemid = detail.ProductId,
                                quantity      = detail.Quantity,
                                Price         = int.Parse(detail.Price + ""),
                                AmountNoTax   = detail.Price,
                                Tax           = 0,
                                TotalAmount   = (detail.Price * detail.Quantity),
                                DateCreated   = DateTime.Now,
                                DatePayment   = DateTime.ParseExact(model.SPayTime, "dd/MM/yyyy hh:mm:ss", null),
                                TypeOrder     = 1,
                                CreatorID     = comm.GetUserId(),
                                StoreID       = 0
                            };
                            db.Insert(objDetail, selectIdentity: true);
                        }
                    }
                    #endregion
                    return(objInsert);
                }
            }
            catch (Exception)
            {
                return(null);
            }
        }
Esempio n. 19
0
        public OperationResult <bool> SaveCustomer(int franchiseId, tbl_Customer customer, tbl_Locations location,
                                                   tbl_Contacts primaryContact, tbl_Contacts secondaryContact,
                                                   bool isBillTo)
        {
            const int findByNameMaxLength = 150;

            try
            {
                using (var tScope = new TransactionScope())
                {
                    using (var dbContext = new EightHundredEntities(UserKey))
                    {
                        if (customer.CustomerID != 0)
                        {
                            var existingCust = dbContext.tbl_Customer.Single(c => c.CustomerID == customer.CustomerID);
                            dbContext.ApplyCurrentValues(existingCust.EntityKey.EntitySetName, customer);
                        }
                        else
                        {
                            dbContext.tbl_Customer.AddObject(customer);
                            var info = tbl_Customer_Info.Createtbl_Customer_Info(0, franchiseId, customer.CustomerID, 1, 1, 2, 1, 0);
                            customer.tbl_Customer_Info.Add(info);
                        }

                        customer.FindByName = !string.IsNullOrWhiteSpace(customer.CustomerName)
                                                  ? !string.IsNullOrWhiteSpace(customer.CompanyName)
                                                        ? (customer.CustomerName + " " + customer.CompanyName).Substring
                                                  (0)
                                                        : customer.CustomerName
                                                  : !string.IsNullOrWhiteSpace(customer.CompanyName)
                                                        ? customer.CompanyName
                                                        : string.Empty;
                        customer.FindByName = customer.FindByName.Substring(0,
                                                                            Math.Min(findByNameMaxLength,
                                                                                     customer.FindByName.Length));

                        dbContext.SaveChanges();

                        tbl_Locations otherLocation;

                        if (location.LocationID != 0)
                        {
                            var existingLoc = dbContext.tbl_Locations.Single(l => l.LocationID == location.LocationID);
                            dbContext.ApplyCurrentValues(existingLoc.EntityKey.EntitySetName, location);

                            otherLocation =
                                dbContext.tbl_Locations.SingleOrDefault(
                                    ol =>
                                    ol.LocationID != location.LocationID &&
                                    (ol.ActvieCustomerID == customer.CustomerID ||
                                     ol.BilltoCustomerID == customer.CustomerID));
                        }
                        else
                        {
                            if (isBillTo)
                            {
                                location.BilltoCustomerID = customer.CustomerID;
                                otherLocation             =
                                    dbContext.tbl_Locations.SingleOrDefault(
                                        ol => ol.ActvieCustomerID == customer.CustomerID);
                            }

                            else
                            {
                                location.ActvieCustomerID = customer.CustomerID;
                                otherLocation             =
                                    dbContext.tbl_Locations.SingleOrDefault(
                                        ol => ol.BilltoCustomerID == customer.CustomerID);
                            }

                            dbContext.tbl_Locations.AddObject(location);
                            dbContext.SaveChanges();
                        }

                        if (primaryContact.ContactID != 0)
                        {
                            var existingContact =
                                dbContext.tbl_Contacts.Single(c => c.ContactID == primaryContact.ContactID);
                            dbContext.ApplyCurrentValues(existingContact.EntityKey.EntitySetName, primaryContact);
                        }
                        else
                        {
                            primaryContact.CustomerID = customer.CustomerID;
                            primaryContact.LocationID = location.LocationID;
                            dbContext.tbl_Contacts.AddObject(primaryContact);
                        }

                        if (secondaryContact != null)
                        {
                            if (secondaryContact.ContactID != 0)
                            {
                                var existingContact =
                                    dbContext.tbl_Contacts.Single(c => c.ContactID == secondaryContact.ContactID);
                                dbContext.ApplyCurrentValues(existingContact.EntityKey.EntitySetName, secondaryContact);
                            }
                            else
                            {
                                secondaryContact.CustomerID = customer.CustomerID;
                                secondaryContact.LocationID = location.LocationID;
                                dbContext.tbl_Contacts.AddObject(secondaryContact);
                            }
                        }

                        dbContext.SaveChanges();

                        var duplicateContacts = false;

                        if (otherLocation == null)
                        {
                            dbContext.SaveChanges();

                            otherLocation = dbContext.tbl_Locations.Single(l => l.LocationID == location.LocationID);
                            dbContext.Detach(otherLocation);

                            if (otherLocation.BilltoCustomerID.HasValue)
                            {
                                otherLocation.ActvieCustomerID = otherLocation.BilltoCustomerID;
                                otherLocation.BilltoCustomerID = null;
                            }
                            else
                            {
                                otherLocation.BilltoCustomerID = otherLocation.ActvieCustomerID;
                                otherLocation.ActvieCustomerID = null;
                            }

                            dbContext.tbl_Locations.AddObject(otherLocation);
                            duplicateContacts = true;
                        }

                        if (duplicateContacts)
                        {
                            dbContext.SaveChanges();

                            if (primaryContact.EntityState != EntityState.Detached)
                            {
                                dbContext.Detach(primaryContact);

                                primaryContact.LocationID = otherLocation.LocationID;
                                primaryContact.ContactID  = 0;
                                dbContext.tbl_Contacts.AddObject(primaryContact);
                            }

                            if (secondaryContact != null && secondaryContact.EntityState != EntityState.Detached)
                            {
                                dbContext.Detach(secondaryContact);
                                secondaryContact.LocationID = otherLocation.LocationID;
                                secondaryContact.ContactID  = 0;
                                dbContext.tbl_Contacts.AddObject(secondaryContact);
                            }
                        }

                        dbContext.SaveChanges();
                        tScope.Complete();
                    }
                }

                return(new OperationResult <bool> {
                    Success = true, ResultData = true
                });
            }
            catch (Exception ex)
            {
                while (ex.InnerException != null)
                {
                    ex = ex.InnerException;
                }

                return(new OperationResult <bool> {
                    Success = false, Message = ex.Message
                });
            }
        }
Esempio n. 20
0
 public bool ValidatedLogin(tbl_Customer login)
 {
     return(entities.tbl_Customer.Count(l => l.Email == login.Email && l.Password == login.Password) > 0);
 }
Esempio n. 21
0
        public BaseOutput AddCustomerWithUser(Customer item, out Customer itemOut)
        {
            CRUDOperation cRUDOperation = new CRUDOperation();
            BaseOutput    baseOutput;

            itemOut = null;
            try
            {
                tbl_EnumValue enumValue = cRUDOperation.GetEnumValueByName("Customer");

                tbl_User user = new tbl_User()
                {
                    UserName      = item.UserName,
                    Password      = UserUtil.MD5HashedPassword(item.Password),
                    UserType_EVID = enumValue.ID,
                };
                tbl_User _User = cRUDOperation.GetUserByUserName(user.UserName);
                if (_User == null)
                {
                    tbl_User userDB = cRUDOperation.AddUser(user);
                    if (userDB != null)
                    {
                        tbl_Customer customer = new tbl_Customer()
                        {
                            UserId       = userDB.ID,
                            Name         = item.Name,
                            Surname      = item.Surname,
                            FatherName   = item.FatherName,
                            IdentityCode = item.IdentityCode,
                            PhoneNumber  = item.PhoneNumber,
                            Email        = item.Email,
                            RegionId     = item.RegionId,
                            Address      = item.Address
                        };
                        tbl_Customer customerDB = cRUDOperation.AddCustomer(customer);

                        if (customerDB != null)
                        {
                            itemOut = new Customer()
                            {
                                UserID       = customerDB.UserId,
                                UserName     = userDB.UserName,
                                CustomerID   = customerDB.ID,
                                Name         = customerDB.Name,
                                Surname      = customerDB.Surname,
                                FatherName   = customerDB.FatherName,
                                IdentityCode = customerDB.IdentityCode,
                                PhoneNumber  = customerDB.PhoneNumber,
                                Email        = customerDB.Email,
                                RegionId     = customerDB.RegionId == null ? 0 : (Int64)customerDB.RegionId,
                                Address      = customerDB.Address
                            };
                        }
                    }
                }

                return(baseOutput = new BaseOutput(true, BOResultTypes.Success.GetHashCode(), BOBaseOutputResponse.SuccessResponse, ""));
            }
            catch (Exception ex)
            {
                return(baseOutput = new BaseOutput(false, BOResultTypes.Danger.GetHashCode(), BOBaseOutputResponse.DangerResponse, ex.Message));
            }
        }
        public JsonRs AddUsingRoom(CustomeCheckInModel obj)
        {
            var rs = new JsonRs();


            using (var db = _connectionData.OpenDbConnection())
            {
                if (obj.CustomerId > 0)
                {
                    try
                    {
                        var usingroom = new tbl_RoomUsing();
                        usingroom.SysHotelID  = comm.GetHotelId();// obj.SysHotelID;
                        usingroom.CheckInID   = obj.CheckInID;
                        usingroom.customerid  = obj.CustomerId;
                        usingroom.datecreated = DateTime.Now;
                        usingroom.roomid      = obj.Roomid;
                        usingroom.status      = 2;
                        db.Insert(usingroom);
                        rs.Status  = "01";
                        rs.Message = "Thêm mới khách ở cùng thàng công.";
                        return(rs);
                    }
                    catch (Exception e)
                    {
                        rs.Status  = "00";
                        rs.Message = "Thêm mới khách ở cùng thất bại!";
                        return(rs);
                    }
                }
                else
                {
                    using (var tran = db.OpenTransaction())
                    {
                        DateTime DOB;
                        DateTime.TryParse(obj.DOB, CultureInfo.GetCultureInfo("vi-vn"), DateTimeStyles.None, out DOB);
                        try
                        {
                            var Customer = new tbl_Customer();
                            Customer.Name           = obj.Name;
                            Customer.CountryId      = obj.CountryId;
                            Customer.DOB            = DOB;
                            Customer.Address        = obj.Address;
                            Customer.Sex            = obj.Sex;
                            Customer.TeamSTT        = obj.TeamSTT;
                            Customer.TeamMergeSTT   = obj.TeamMergeSTT;
                            Customer.Email          = obj.Email;
                            Customer.IdentifyNumber = obj.IdentifyNumber;
                            Customer.Phone          = obj.Phone;
                            Customer.Address        = obj.Address;
                            Customer.Company        = obj.Company;
                            Customer.Status         = true;
                            Customer.TeamMergeSTT   = obj.TeamMergeSTT;
                            Customer.TeamSTT        = obj.TeamSTT;
                            Customer.Payer          = 0;
                            Customer.Status         = true;
                            Customer.ReservationID  = obj.CheckInID;
                            Customer.HotelCode      = comm.GetHotelCode();
                            Customer.SysHotelID     = comm.GetHotelId();

                            long idCustomer = db.Insert(Customer, true);

                            var usingroom = new tbl_RoomUsing();
                            usingroom.SysHotelID   = comm.GetHotelId();//Customer.SysHotelID;
                            usingroom.SysHotelCode = comm.GetHotelCode();
                            usingroom.CheckInID    = obj.CheckInID;
                            usingroom.customerid   = (int)idCustomer;// Customer.Id;
                            usingroom.datecreated  = DateTime.Now;
                            usingroom.roomid       = obj.Roomid;
                            usingroom.status       = 2;
                            db.Insert(usingroom);

                            /*
                             * var group = new tbl_CustomerGroup();
                             * group.Doan_ID = obj.TeamSTT;
                             * group.Gop_Doan_ID = obj.TeamMergeSTT;
                             * group.Customer_ID = Customer.Id;
                             * db.Insert(group);
                             */

                            tran.Commit();
                            rs.Status  = "01";
                            rs.Message = "Thêm mới khách ở cùng thàng công.";
                            return(rs);
                        }
                        catch (Exception)
                        {
                            tran.Rollback();
                            rs.Status  = "00";
                            rs.Message = "Thêm mới khách ở cùng thất bại!";
                            return(rs);
                        }
                    }
                }
            }
        }
Esempio n. 23
0
 public void update(tbl_Customer item)
 {
     rep.update(item);
 }
Esempio n. 24
0
 protected void btn_signup_Click(object sender, EventArgs e)
 {
     try
     {
         if (txt_userNameReg.Text.Length > 0)
         {
             if (txt_PassReg.Text.Length > 0)
             {
                 if (txt_EmailReg.Text.Length > 0)
                 {
                     if (txt_NameReg.Text.Length > 0)
                     {
                         if (txtPhonReg.Text.Length > 0)
                         {
                             if (txt_PassReg.Text.Equals(txt_RePassReg.Text))
                             {
                                 tbl_Customer tk = new tbl_Customer();
                                 tk.Email    = txt_EmailReg.Text;
                                 tk.Usermame = txt_userNameReg.Text;
                                 tk.Password = txt_PassReg.Text.GetMD5();
                                 tk.Phone    = Int32.Parse(txtPhonReg.Text);
                                 tk.FullName = txt_NameReg.Text;
                                 tk.Address  = txtAddressReg.Text;
                                 tk.UserID   = 2;
                                 tk.IsLock   = false;
                                 tk.IsDelete = false;
                                 db.tbl_Customer.Add(tk);
                                 db.SaveChanges();
                                 Response.Redirect("DkThanhCong.aspx");
                             }
                             else
                             {
                                 msg.Text      = "Mật khẩu không trùng khớp.";
                                 msg.ForeColor = System.Drawing.Color.Red;
                             }
                         }
                         else
                         {
                             msg.Text      = "Bạn chưa nhập số điện thoại";
                             msg.ForeColor = System.Drawing.Color.Red;
                         }
                     }
                     else
                     {
                         msg.Text      = "Bạn chưa nhập họ tên";
                         msg.ForeColor = System.Drawing.Color.Red;
                     }
                 }
                 else
                 {
                     msg.Text      = "Bạn chưa nhập email";
                     msg.ForeColor = System.Drawing.Color.Red;
                 }
             }
             else
             {
                 msg.Text      = "Bạn chưa nhập mật khẩu";
                 msg.ForeColor = System.Drawing.Color.Red;
             }
         }
         else
         {
             msg.Text      = "Bạn chưa nhập tài khoản";
             msg.ForeColor = System.Drawing.Color.Red;
         }
     }
     catch (Exception ex)
     {
         msg.Text      = "Đã xảy ra lỗi. Vui lòng thử lại sau. " + ex.Message;
         msg.ForeColor = System.Drawing.Color.Red;
     }
 }
        public BaseResponse RedeemReferralSubscription(int referralid, string firstname, string lastname,
                                                       string emailaddress, string countrycode, string address1, string address2,
                                                       string city, string region, string postal, bool optin, string username, string password)
        {
            List <Message> errors    = new List <Message>();
            string         errortext = string.Empty;

            try
            {
                HarperLINQ.Referral referral;

                #region input validation
                using (AHT_MainDataContext context = new AHT_MainDataContext(ConfigurationManager.ConnectionStrings["AHT_MainConnectionString"].ConnectionString))
                {
                    referral = context.Referrals.SingleOrDefault(r => r.id == referralid);
                }
                if (referral == null)
                {
                    errortext = string.Format(BusinessLogicStrings.invalidReferralIdError, referralid);
                    errors.Add(new Message(MessageSources.AndrewHarper, 0, "RedeemReferralException", errortext, "", "", null));
                }
                else if (referral.dateredeemed != null || referral.friendid > 0)
                {
                    errortext = string.Format(BusinessLogicStrings.RedeemedReferralError, referralid);
                    errors.Add(new Message(MessageSources.AndrewHarper, 0, "RedeemReferralException", errortext, "", "", null));
                }
                else if (referral.dateexpires <= DateTime.Now)
                {
                    errortext = string.Format(BusinessLogicStrings.expiredReferralError, referralid);
                    errors.Add(new Message(MessageSources.AndrewHarper, 0, "RedeemReferralException", errortext, "", "", null));
                }
                #endregion

                else
                {
                    #region sub order insert
                    Member giftData = new Member();
                    giftData.FirstName = firstname;
                    giftData.LastName  = lastname;
                    giftData.OptIn     = optin;
                    giftData.Email     = emailaddress;

                    giftData.Address            = new Address();
                    giftData.Address.Address1   = address1;
                    giftData.Address.Address2   = address2;
                    giftData.Address.City       = city;
                    giftData.Address.State      = region;
                    giftData.Address.PostalCode = postal;
                    giftData.Address.Country    = countrycode;

                    SubscriptionServiceRequest request = new SubscriptionServiceRequest(referral, giftData);
                    baseResponse = SubOrderInsert.RedeemReferralSubscription(request);
                    foreach (Message err in baseResponse.Messages)
                    {
                        errors.Add(err);
                    }
                    #endregion

                    MembershipLogic memberlogic    = new MembershipLogic();
                    BaseResponse    memberResponse = null;
                    if (errors.Count <= 0)
                    {
                        memberResponse = memberlogic.GetMemberByUserName(emailaddress);
                    }

                    if (!(errors.Count > 0 ||
                          memberResponse == null ||
                          memberResponse.TypedResponse == null ||
                          memberResponse.TypedResponse.Success == false))
                    {
                        using (AHT_MainDataContext context = new AHT_MainDataContext(ConfigurationManager.ConnectionStrings["AHT_MainConnectionString"].ConnectionString))
                        {
                            GetMemberResponse getMemberResponse = memberResponse.TypedResponse as GetMemberResponse;
                            if (getMemberResponse.MemberFound && getMemberResponse.MemberData != null)
                            {
                                string newMemberId = getMemberResponse.MemberData.MemberId;

                                #region create the user at AH
                                object[] create_response = tbl_Customer.CreateCustomer(address1, address2, "", city, region,
                                                                                       countrycode, postal, "Z1", password, "PERSONAL", "",
                                                                                       firstname, "", lastname, "", emailaddress, username, newMemberId, referral.pubcode, DateTime.Now.AddMonths(referral.subscriptionlength).ToShortDateString(), DateTime.Now.ToShortDateString(), username, "");
                                tbl_Customer customer = (tbl_Customer)create_response[1];
                                #endregion

                                #region referral data at AH
                                referral = context.Referrals.SingleOrDefault(r => r.id == referralid);
                                referral.dateredeemed = DateTime.Now;
                                referral.friendid     = customer.cusID;
                                context.SubmitChanges();
                                #endregion

                                #region send email
                                Mailer mailer = new Mailer();

                                mailer.SendEmail(
                                    ConfigurationManager.AppSettings["mailserviceuser"],
                                    ConfigurationManager.AppSettings["mailservicepwd"],
                                    "Welcome to the Andrew Harper Community!",
                                    ConfigurationManager.AppSettings["referemailfrom"],
                                    referral.friendemail,
                                    string.Empty,
                                    string.Empty,
                                    referral.GetReferralUserCreatedEmailBody(),
                                    true,
                                    ConfigurationManager.AppSettings["smtpserver"]);
                                #endregion
                            }
                        }
                    }
                    else
                    {
                        errortext = string.Format(BusinessLogicStrings.RetrieveMemeberError, new object[] { referralid, emailaddress });
                        errors.Add(new Message(MessageSources.AndrewHarper, 0, "RedeemReferralException", errortext, "", "", null));
                    }
                }

                baseResponse.TypedResponse = new AHResponse();
                if (errors.Count == 0)
                {
                    baseResponse.TypedResponse.Success = true;
                }
                else
                {
                    baseResponse.TypedResponse.Success = false;
                }
            }

            catch (Exception ex)
            {
                baseResponse.TypedResponse.Success = false;
                errortext = string.Format(BusinessLogicStrings.UnknownReferralError, ex.Message);
                errors.Add(new Message(MessageSources.AndrewHarper, 0, "RedeemReferralException", errortext, "", "", null));
            }
            foreach (Message error in errors)
            {
                if (baseResponse == null)
                {
                    baseResponse = new BaseResponse();
                }
                baseResponse.Messages.Add(error);

                StringBuilder error_text = new StringBuilder();
                error_text.AppendLine("REFERRAL ERROR LOGGED");
                error_text.AppendLine(string.Format("REFERRALID {0}", referralid));
                baseResponse.Messages.Add(error);
                error_text.AppendLine(string.Format("ERROR: ", new object[] { }));
                EventLogger.LogError("SubscriptionLogic.RedeemReferralSubscription", error_text.ToString(), true);
            }
            return(baseResponse);
        }