コード例 #1
0
        public ActionResult Create([Bind(Include = "FirstName,LastName,EmailId,Password,Address,City,State,Country,ZipCode,Mobile")] RegisterViewModel viewModel)
        {
            try
            {

                if (ModelState.IsValid)
                {

                    Data.User user = new Data.User();
                    Data.UserAddress userAddress = new UserAddress();

                  //  ShippingAddressRepository shReop = new ShippingAddressRepository();

                     user.FirstName = viewModel.FirstName;
                     user.LastName = viewModel.LastName;
                     user.EmailId = viewModel.EmailId;
                     user.Password = viewModel.Password;
                     user.Role = "U";
                     user.UserName = viewModel.FirstName + " " + viewModel.LastName;

                     if (!userRepo.VerifyEmail(viewModel.EmailId))
                     {
                         userRepo.Create(user);
                         int userId = userRepo.GetByEmail(viewModel.EmailId).PKUserId;
                         userAddress.FKUserId = userId;
                         userAddress.Address = viewModel.Address;
                         userAddress.City = viewModel.City;
                         userAddress.State = viewModel.State;
                         userAddress.Country = viewModel.Country;
                         userAddress.ZipCode = viewModel.ZipCode;
                         userAddress.Mobile = viewModel.Mobile;
                         sAddresRepo.Create(userAddress);

                         TempData["Msg"] = "Created Successfully";

                         return RedirectToAction("Index");
                     }
                     else
                     {
                         TempData["Msg"] = "Email already exits";

                         return RedirectToAction("Index");
                     }

                }
                else
                {
                    return View("Index");
                }
            }
            catch (Exception e)
            {
                TempData["Msg"] = "Create Failed : " + e.Message;
                return RedirectToAction("Index");
            }
        }
コード例 #2
0
 public void Update(UserAddress UserAddress)
 {
     shoppingCardDB.Entry(UserAddress).State = EntityState.Modified;
     Save();
 }
コード例 #3
0
 public void Create(UserAddress UserAddress)
 {
     shoppingCardDB.UserAddresses.Add(UserAddress);
     Save();
 }
コード例 #4
0
ファイル: OrderController.cs プロジェクト: mahmoodali31/shop
        public ActionResult OrderDetail(OrderViewModel model)
        {
            OrderRepository orderRepo = new OrderRepository();
            OrderDetailRepository orderDetailRepo = new OrderDetailRepository();

            ShippingAddressRepository shARepo = new ShippingAddressRepository();

            Data.Order order = new Order();

            Data.OrderDetail orderDetail = new Data.OrderDetail();

            UserAddress userAddress = new UserAddress();

            IEnumerable<Data.User> userList =userRepo.GetAllUsers();

            Data.User user = new Data.User();

            string body = null;

            using (StreamReader sr = new StreamReader(Server.MapPath("~/Template/EmailTemp.html")))
            {
                body = sr.ReadToEnd();

            }

            if (User.Identity.IsAuthenticated)
            {

                string userEmail = User.Identity.Name;
                currentUer = userRepo.GetByEmail(userEmail);

                order.FKUserId = currentUer.PKUserId;

                int orderId = orderRepo.Create(order);
                order.User = currentUer;

                productId = (IList<string>)Session["ProId"];

                foreach (var item in productId)
                {
                    int id = Convert.ToInt32(item);
                    orderDetail.FKOrderId = orderId;
                    orderDetail.FKProductId = id;
                    orderDetail.Status = "In Store";
                    orderDetail.Quantity = (int)prodReop.GetById(id).Quantity;
                    orderDetail.Cost = (decimal)prodReop.GetById(id).Price;

                    orderDetailRepo.Create(orderDetail);

                }
                model.UserName = currentUer.FirstName+" "+currentUer.LastName;
                userAddress = shARepo.GetAddressByUserId(currentUer.PKUserId);
                model.Address = userAddress.Address;
                model.Mobile = userAddress.Mobile;
                AddCart();
                model.Carts = cartReop.GetCartItems(currentUer.PKUserId);
                model.SubPrice = cart.Quantity * cart.Price;
                model.TotalPrice = Convert.ToDecimal(GetItemsPrice());
                TempData["Tax"] = .25;

               body = body.Replace("[UserName]", currentUer.FirstName + " " + currentUer.LastName);
                body = body.Replace("[Mobile]", userAddress.Mobile);
                body = body.Replace("[Adderss]", userAddress.Address);
                body = body.Replace("[Date]", DateTime.Now.ToString());
                body = RazorEngine.Razor.Parse(body, model);

                body = body.Replace("[SubPrice]", model.SubPrice.ToString());
                //body = body.Replace("[Tax]", tax.ToString());
                body = body.Replace("[TotalPrice]", model.TotalPrice.ToString());

                EmailUtility.SendEmail(userEmail, "E-Shop", body, null);
                cartReop.EmptyCart(currentUer.PKUserId);

                return View("OrderDetail", model);
            }

            else
            {
                user.UserName = model.FirstName + " " + model.LastName;
                user.FirstName = model.FirstName;
                user.LastName = model.LastName;
                user.EmailId = model.Email;
                user.Password = model.Password;
                user.Role = "U";
                userId = userRepo.Create(user);
                order.FKUserId = userId;
                int orderId = orderRepo.Create(order);
                productId = (IList<string>)Session["ProId"];

                foreach (var item in productId)
                {
                    int id = Convert.ToInt32(item);
                    orderDetail.FKOrderId = orderId;
                    orderDetail.FKProductId = id;
                    orderDetail.Status = "In Store";
                    orderDetail.Quantity = (int)prodReop.GetById(id).Quantity;
                    orderDetail.Cost = (decimal)prodReop.GetById(id).Price;
                    orderDetailRepo.Create(orderDetail);

                }
                userAddress.FKUserId = userId;
                userAddress.Address = model.Address;
                userAddress.City = model.City;
                userAddress.State = model.State;
                userAddress.Mobile = model.Mobile;
                userAddress.Country = model.Country;

                userAddress.ZipCode = Convert.ToInt32(model.Zipcode);
                shARepo.Create(userAddress);

                TempData["UserName"] = model.FirstName + " " + model.LastName;
                TempData["Adderss"] = model.Address;
                TempData["Mobile"] = model.Mobile;
                TempData["Tax"] = .25;
                AddCart();
                model.Carts = cartReop.GetCartItems(userId);
                model.SubPrice = cart.Quantity * cart.Price;
                model.TotalPrice = Convert.ToDecimal(GetItemsPrice());

                decimal tax = Convert.ToDecimal(model.TotalPrice) * Convert.ToDecimal(.25f);

                body = body.Replace("[UserName]", model.FirstName + " " + model.LastName);
                body = body.Replace("[Mobile]", model.Mobile);
                body = body.Replace("[Adderss]", model.Address);
                body = body.Replace("[Date]", DateTime.Now.ToString());
                body = RazorEngine.Razor.Parse(body, model);

                body = body.Replace("[SubPrice]", model.SubPrice.ToString());
                body = body.Replace("[Tax]", tax.ToString());
                body = body.Replace("[TotalPrice]", model.TotalPrice.ToString());

               EmailUtility.SendEmail(model.Email, "E-Shop", body, null);
               cartReop.EmptyCart(userId);

                return PartialView("_OrderDetail", model);
            }
        }