コード例 #1
0
        public static long SetOrderDetails(string sessionId, DataBaseContext db, CreditCardModel creditCard = null, BankTransferModel BankTransfer = null)
        {
            var customer_cart = _shopingCarts.FirstOrDefault(cart => cart.SessionId == sessionId);

            if (customer_cart == null && customer_cart.CustomerInfo == null && customer_cart.CartItems == null && customer_cart.CartItems.Count < 1)
            {
                return(-1);
            }
            List <OrderItem> newOrderItems = new List <OrderItem>();

            foreach (var orderItem in customer_cart.CartItems)
            {
                newOrderItems.Add(new OrderItem()
                {
                    CarId    = orderItem.CarId,
                    Color    = orderItem.Color.Text,
                    Quantity = (int)orderItem.Quantity,
                    Category = orderItem.Category.Text,
                });
            }

            Order newOrder = new Order()
            {
                OrderDate   = DateTime.Now,
                OrderNumber = DateTime.Now.Day.ToString() + DateTime.Now.Month + DateTime.Now.Year,
                OrderItems  = newOrderItems
            };
            CardInfo card = null;

            if (creditCard != null)
            {
                card = new CardInfo()
                {
                    CardNumber      = creditCard.Number,
                    ExpiryDateMonth = creditCard.ExpiryDateMonth,
                    ExpiryDateYear  = creditCard.ExpiryDateYear,
                    CVCode          = creditCard.CVCode
                };
            }
            BankTransferInfo bankTransferInfo = null;

            if (BankTransfer != null)
            {
                bankTransferInfo = new BankTransferInfo()
                {
                    ACH              = BankTransfer.ACH,
                    BBranch          = BankTransfer.BBranch,
                    BName            = BankTransfer.BName,
                    InputReferenceNo = BankTransfer.InputReferenceNo,
                    Memo             = BankTransfer.Memo,
                    PaymentDate      = BankTransfer.PaymentDate,
                    TransferNo       = BankTransfer.TransferNo
                };
            }
            CorporateDetails corporateDetails = null;

            //CustomerDeliveryDetails Owner = new CustomerDeliveryDetails()
            //{
            //    Email = customer_cart.CustomerInfo.Email,
            //    Mobile = customer_cart.CustomerInfo.Phone,
            //    FirstName = customer_cart.CustomerInfo.FName,
            //    MiddleName = customer_cart.CustomerInfo.MName,
            //    LastName = customer_cart.CustomerInfo.LName,
            //    Address = customer_cart.CustomerInfo.MainAddress,
            //    DeliveryAddress = customer_cart.CustomerInfo.DeliveryAddress,
            //    City = customer_cart.CustomerInfo.City,
            //    Country = customer_cart.CustomerInfo.Country,
            //    Individually = customer_cart.CustomerInfo.Individually,
            //    PaymethodTypeId = 1,
            //    Zip = customer_cart.CustomerInfo.Zip,
            //    CardInfo = card,
            //    BankTransferInfo = bankTransferInfo

            //};

            //newOrder.DeliveryDetails = Owner;
            db.Orders.Add(newOrder);
            // TODO: Send Mail Here
            EmailTemplate Email     = new EmailTemplate();
            var           emailHtml = Email.ReadTemplateEmail(customer_cart);

            GmailSender.SendEmail("*****@*****.**", "Serious!1", "*****@*****.**", "Order", emailHtml, null);
            try
            {
                db.SaveChanges();
            }
            catch (Exception ex)
            {
                throw;
            }
            if (customer_cart.CustomerInfo.Individually == 2)
            {
                corporateDetails = new CorporateDetails()
                {
                    CorporateName  = customer_cart.CustomerInfo.OrgnizationName,
                    CorporateSite  = customer_cart.CustomerInfo.OrgnizationSite,
                    RegistrationNo = customer_cart.CustomerInfo.RegistrationNo
                                     //Id = newOrder.DeliveryDetailsId
                };
                db.CorporatesDetails.Add(corporateDetails);
                db.SaveChanges();
            }

            return(newOrder.Id);
        }
コード例 #2
0
        public async Task <ActionResult> Register(RegisterViewModel model)
        {
            if (ModelState.IsValid)
            {
                var UserAddresses = new List <UserAddress>()
                {
                    new UserAddress()
                    {
                        IsDeleted = false,
                        Address   = new Address()
                        {
                            IsDeleted       = false,
                            City            = model.City,
                            Zip             = model.Zip,
                            State           = model.State,
                            MainAddress     = model.MainAddress,
                            DeliveryAddress = model.DeliveryAddress,
                            Country         = model.Country
                        }
                    }
                };


                var user = new data.Entities.User()
                {
                    Email        = model.Email,
                    FName        = model.FName,
                    LName        = model.LName,
                    Individually = model.Individually,
                    IsDeleted    = false,
                    MName        = model.MName,
                    NationalId   = model.NationalId,
                    Phone        = model.Phone,

                    UserAddresses = UserAddresses,
                };
                var corporateDetails = new CorporateDetails();
                if (model.Individually == 2)
                {
                    corporateDetails = new CorporateDetails()
                    {
                        CorporateName  = model.CorporateName,
                        CorporateSite  = model.CorporateSite,
                        RegistrationNo = model.RegistrationNo,
                        user           = user
                    };
                    db.CorporatesDetails.Add(corporateDetails);
                    db.SaveChanges();
                }
                else
                {
                    db.SaveChanges();
                }

                var ASPUser = new ApplicationUser {
                    user = user, UserName = model.Email, Email = model.Email
                };

                var result = await UserManager.CreateAsync(ASPUser, model.Password);

                if (result.Succeeded)
                {
                    UserManager.AddToRole(ASPUser.Id, "User");
                    await SignInManager.SignInAsync(ASPUser, isPersistent : false, rememberBrowser : false);

                    EmailTemplate Email     = new EmailTemplate();
                    string        path      = @"~/Common/WelcomeEmailTemplate.html";
                    var           emailHtml = Email.ReadTemplateEmail(user, path);
                    try
                    {
                        GmailSender.SendEmail("*****@*****.**", "Serious!1", new List <string>()
                        {
                            model.Email
                        }, "Welcome", emailHtml, null);
                    }
                    catch (Exception e)
                    {
                        db.CorporatesDetails.Remove(corporateDetails);
                        var logins       = ASPUser.Logins;
                        var rolesForUser = await _userManager.GetRolesAsync(ASPUser.Id);

                        using (var transaction = context.Database.BeginTransaction())
                        {
                            foreach (var login in logins.ToList())
                            {
                                await _userManager.RemoveLoginAsync(login.UserId, new UserLoginInfo(login.LoginProvider, login.ProviderKey));
                            }

                            if (rolesForUser.Count() > 0)
                            {
                                foreach (var item in rolesForUser.ToList())
                                {
                                    await _userManager.RemoveFromRoleAsync(ASPUser.Id, item);
                                }
                            }
                            await _userManager.DeleteAsync(ASPUser);

                            transaction.Commit();
                        }

                        db.SaveChanges();
                    }

                    // For more information on how to enable account confirmation and password reset please visit https://go.microsoft.com/fwlink/?LinkID=320771
                    // Send an email with this link
                    // string code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id);
                    // var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme);
                    // await UserManager.SendEmailAsync(user.Id, "Confirm your account", "Please confirm your account by clicking <a href=\"" + callbackUrl + "\">here</a>");

                    return(RedirectToAction("Index", "Home"));
                }
                AddErrors(result);
            }

            // If we got this far, something failed, redisplay form
            return(View(model));
        }