Exemplo n.º 1
0
        [ValidateAntiForgeryToken]//TODO check this
        public ActionResult RegisterSave(RegisterModel registerModel)
        {
            var salt = GenerateSalt();

            var person = new Person()
            {
                Password   = registerModel.Password,
                CreateDate = DateTime.Now,
                CreatedBy  = registerModel.FirstName + registerModel.LastName,
                EmailId    = registerModel.EmailId,
                LastName   = registerModel.LastName,
                FirstName  = registerModel.FirstName,
                UserName   = registerModel.EmailId,
                Salt       = Convert.ToBase64String(salt)
            };
            var password = GenerateHash(salt, registerModel.Password);

            person.Password = password;
            var address = new Address()
            {
                AddressLine1 = registerModel.InputAddress,
                AddressLine2 = registerModel.InputAddress2,
                ApartmentNo  = registerModel.ApartmentNo,
                CreateDate   = DateTime.Now,
                PoBox        = registerModel.PoBox,
                HouseNo      = registerModel.HouseNo,
                State        = registerModel.InputState,
                UpdatedBy    = registerModel.FirstName,
                UpdateDate   = DateTime.Now,
                ZipCode      = registerModel.InputZip,
                City         = registerModel.City
            };


            using (var trans = _saveToDatabase.GetTraction())
            {
                _saveToDatabase.Save(person);
                address.PersonId = person.Id;
                _saveToDatabase.Save(address);
                trans.Complete();
            }

            TempData["UserMessage"] = new SuccessMessage {
                CssClassName = "alert alert-success", Title = "Register Successful", Message = "Operation Done."
            };
            return(RedirectToAction("Index", "Home"));
        }
Exemplo n.º 2
0
        public void DownloadAndSave()
        {
            string data1 = null;
            string data2 = null;

            Parallel.Invoke(
                () => data1 = _downloadFromInternet1.Download(),
                () => data2 = _downloadFromInternet2.Download());
            _saveToDatabase.Save(data1 + data2);
        }
        public ActionResult Checkout(FullCheckOutModel checkoutModel)
        {
            try
            {
                Person personAddress = null;
                var    user          = _loggedInUser.GetLoggedInUser(System.Web.HttpContext.Current);

                if (user == null)
                {
                    throw new HttpException("Unable to find User");
                }

                //instead of this in future pull from cache, when an record in updated in database  insert to other table called cache and then have a windows service check that every 1 sec
                var listOfProducts = new Dictionary <long, long>();
                foreach (var productsData in checkoutModel.ProductsData)
                {
                    if (productsData.ProductData != null)
                    {
                        listOfProducts.Add(productsData.ProductData.Id, productsData.Quantity);
                    }
                }

                var products          = new ProductsQuery().GetFromDatabase(listOfProducts.Keys.ToList());
                var sameAsHomeAddress = checkoutModel.SameAddress;
                if (sameAsHomeAddress)
                {
                    personAddress = new PersonQuery().GetPersonWithAddress(user.Id);
                }
                using (var transaction = _saveToDatabase.GetTraction())
                {
                    decimal totalPayablePrice = 0;
                    var     order             = new Order()
                    {
                        OrderedTime       = DateTime.Now,
                        PersonId          = user.Id,
                        ShippingCharges   = checkoutModel.ShippingCharges,
                        TotalPayablePrice = totalPayablePrice
                    };
                    _saveToDatabase.Save(order);
                    var randorNumber = new Random(12);
                    foreach (var product in products)
                    {
                        var cost = 0M;
                        if (listOfProducts.TryGetValue(product.Id, out var quant))
                        {
                            cost = quant * product.Price;
                            totalPayablePrice = totalPayablePrice + cost;
                            var productOrder = new ProductOrder()
                            {
                                OrderId       = order.Id,
                                OrderDateTime = DateTime.Now,
                                ProductId     = product.Id,
                                Quantity      = quant,
                                Status        = Status.Success,
                                UpdatedBy     = user.FirstName
                            };
                            _saveToDatabase.Save(productOrder);


                            var shippingAddress = new ShippingAddress
                            {
                                AddressLine1 = sameAsHomeAddress ? personAddress.Address.AddressLine1 ?? checkoutModel.AddressLine1 : null,
                                AddressLine2 = sameAsHomeAddress ? personAddress.Address.AddressLine2 ?? checkoutModel.AddressLine2 : null,
                                //  ApartmentNo = checkoutModel.ApartmentNo,
                                CreateDate     = DateTime.Now,
                                CreateDateTime = DateTime.Now,
                                HouseNo        = checkoutModel.HouseNo,
                                //PoBox = checkoutModel.PoBox,
                                ProductOrderId    = productOrder.Id,
                                SameAsHomeAddress = sameAsHomeAddress,
                                State             = sameAsHomeAddress ? personAddress.Address.State ?? checkoutModel.State: null,
                                ZipCode           = sameAsHomeAddress ? personAddress.Address.ZipCode : checkoutModel.ZipCode,
                                ShippingCompany   = "My Company",
                                UpdateDate        = DateTime.Now,
                                UpdatedBy         = "System",
                                TrackingId        = randorNumber.Next(1000) //can call a webservice to shipping company and get data
                            };
                            _saveToDatabase.Save(shippingAddress);
                        }
                    }
                    _saveToDatabase.Update(order);
                    transaction.Complete();
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                throw;
            }

            var actionResult = new JsonResult()
            {
                Data = new { success = "Order Submitted", response = "/products" }, ContentType = "json", JsonRequestBehavior = JsonRequestBehavior.AllowGet
            };

            return(actionResult);
        }
Exemplo n.º 4
0
        public void DownloadAndSave()
        {
            var data = _downloadFromInternet.Download();

            _saveToDatabase.Save(data);
        }