Пример #1
0
        public IActionResult RegisterCompleted(CustomerDTO model)
        {
            var customer = this._context.Customers.Include(i => i.CustomerClass).Include(i => i.User).Where(u => u.Email == model.email).FirstOrDefault();

            if (customer != null)
            {
                model = CustomerBinding.Binding(customer);
            }


            return(View(model));
        }
Пример #2
0
        public async Task <IActionResult> Register(CustomerDTO model, bool repair = false)
        {
            if (ModelState.IsValid)
            {
                if (!repair)
                {
                    if (string.IsNullOrEmpty(model.username))
                    {
                        model.username = model.email;
                    }
                    if (!model.isDhiMember)
                    {
                        model.citizenId = null;
                    }
                    if (this.isExistIDCard(model))
                    {
                        var rg = new RijndaelCrypt();

                        model.ShowIdcardDupPopup = true;
                        var ducus = this._context.Customers.Include(i => i.User).Where(c => c.IDCard == model.citizenId & (model.ID > 0 ? c.ID != model.ID : true));
                        model.dupEmail = new List <string>();
                        model.dupFBID  = new List <string>();
                        foreach (var cus in ducus)
                        {
                            if (string.IsNullOrEmpty(cus.FacebookID))
                            {
                                model.dupEmail.Add(cus.User.UserName);
                            }
                            else
                            {
                                model.dupFBID.Add(cus.User.UserName);
                            }

                            model.dupIdcard = model.citizenId;
                        }
                        ModelState.AddModelError("citizenId", "รหัสบัตรประชาชนซ้ำในระบบ");
                    }
                    if (this.isExistEmail(model))
                    {
                        ModelState.AddModelError("email", "อีเมลซ้ำในระบบ");
                    }
                    if (this.isExistUserName(model))
                    {
                        ModelState.AddModelError("email", "รหัสผู้ใช้งานซ้ำในระบบ");
                    }
                    //if (this.isExistMobileNo(model))
                    //   ModelState.AddModelError("moblieNo", "เบอร์โทรศัพท์ซ้ำในระบบ");
                    //if (this.isExistName(model))
                    //{
                    //   ModelState.AddModelError("firstName", "ชื่อนามสกุลซ้ำในระบบ");
                    //   ModelState.AddModelError("lastName", "ชื่อนามสกุลซ้ำในระบบ");
                    //}
                    if (!string.IsNullOrEmpty(model.friendCode) && !this.isExistFriendCode(model))
                    {
                        ModelState.AddModelError("friendCode", "ไม่พบข้อมูล friend Code");
                    }
                }

                if (ModelState.IsValid)
                {
                    if (model.valid)
                    {
                        model.password = DataEncryptor.Decrypt(model.pEncyprt);
                        var customer = new Customer();
                        customer.Create_On     = DateUtil.Now();
                        customer.ChannelUpdate = CustomerChanal.TIP;
                        customer = CustomerBinding.Binding(customer, model);

                        GetCustomerClass(customer);
                        customer.Create_On = DateUtil.Now();
                        customer.Create_By = customer.User.UserName;
                        customer.Update_On = DateUtil.Now();
                        customer.Update_By = customer.User.UserName;
                        customer.Success   = false;
                        var regs = this.GetPointCondition(customer, TransacionTypeID.Register);
                        foreach (var item in regs)
                        {
                            if (item.Point.Value > 0)
                            {
                                var point = this.GetCustomerPoint(item, customer, item.Point.Value, (int)TransacionTypeID.Register, CustomerChanal.TIP, "tipsociety-register");
                                customer.CustomerPoints.Add(point);
                            }
                        }
                        var      friendpoint = 0;
                        Customer friend      = null;
                        if (!string.IsNullOrEmpty(customer.FriendCode))
                        {
                            var invites = this.GetPointCondition(customer, TransacionTypeID.InviteFriend);
                            foreach (var item in invites)
                            {
                                var p = this.GetPoint(item, customer);
                                if (p > 0)
                                {
                                    var point = this.GetCustomerPoint(item, customer, p, (int)TransacionTypeID.InviteFriend, CustomerChanal.TIP, "tipsociety-register");
                                    friend = this._context.Customers.Where(w => w.RefCode == customer.FriendCode).FirstOrDefault();
                                    if (friend != null)
                                    {
                                        friendpoint      = p;
                                        point.CustomerID = friend.ID;
                                        this._context.CustomerPoints.Add(point);
                                    }
                                }
                            }
                        }
                        this._context.Customers.Add(customer);
                        this._context.SaveChanges();
                        this._context.Entry(customer).GetDatabaseValues();
                        customer.RefCode = CustomerBinding.GetRefCode(customer);
                        this._context.Users.Attach(customer.User);
                        this._context.Entry(customer.User).Property(u => u.Email).IsModified       = true;
                        this._context.Entry(customer.User).Property(u => u.PhoneNumber).IsModified = true;
                        this._context.Update(customer);
                        this._context.SaveChanges();

                        AddConsent(model);

                        if (_conf.SendEmail == true && friend != null && friendpoint > 0)
                        {
                            await MailInviteFriend(friend.Email, friend, customer, friendpoint);
                        }
                        try
                        {
                            if (!repair)
                            {
                                using (var client = new HttpClient())
                                {
                                    client.BaseAddress = new Uri(_mobile.Url + "/rewardpoint/customerprofile/register");
                                    client.DefaultRequestHeaders.Accept.Clear();
                                    client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));

                                    var rg = new RijndaelCrypt();
                                    model.username = rg.Encrypt(model.username);
                                    model.password = rg.Encrypt(model.password);
                                    model.status   = customer.Status.toStatusNameEn();

                                    StringContent content = new StringContent(JsonConvert.SerializeObject(model), Encoding.UTF8, "application/json");

                                    HttpResponseMessage response = await client.PostAsync(client.BaseAddress, content);

                                    if (response.IsSuccessStatusCode && response.StatusCode == HttpStatusCode.OK)
                                    {
                                        customer.Success = true;
                                        this._context.SaveChanges();
                                    }
                                    else
                                    {
                                        _logger.LogWarning(JsonConvert.SerializeObject(model));
                                        _logger.LogWarning(await response.Content.ReadAsStringAsync());
                                    }
                                }
                            }
                        }
                        catch
                        {
                        }
                        if (_conf.SendEmail == true)
                        {
                            await MailActivateAcc(customer.Email, customer.ID);
                        }

                        //if (_conf.SendSMS == true)
                        //   SendSMS(customer.ID);

                        return(await Login(new Login()
                        {
                            UserName = model.email, Password = model.password
                        }, true));
                    }
                    else
                    {
                        model.pEncyprt = DataEncryptor.Encrypt(model.password);
                    }
                    model.valid = true;
                }
            }
            return(View(model));
        }