Beispiel #1
0
        public IActionResult Contact()
        {
            GetAddress addressViewMOdel = new GetAddress();
            var        street           = "ьь";
            var        town             = "ьь";
            var        fullAddress      = "в Системата няма данни за Вашият адрес.";


            if (User.Identity.IsAuthenticated)
            {
                addressViewMOdel.Email = User.Identity.Name;
            }
            var user  = userServices.GetUserByUsername(User.Identity.Name);
            var order = this._orderServices.GetProcessingOrder(this.User.Identity.Name);

            if (order != null)
            {
                var adddress = _addressesServices.GetAllAddresses().Where(x => x.Id == order.DeliveryAddressId);
                foreach (var address in adddress)
                {
                    street      = address.Street + " " + address.BuildingNumber;
                    town        = address.City.Name + " " + address.City.Postcode;
                    fullAddress = street + " " + town;
                    addressViewMOdel.Address = fullAddress;
                }
            }
            else
            {
                addressViewMOdel.Address = fullAddress;
            }

            return(View(addressViewMOdel));
        }
Beispiel #2
0
        public IActionResult Create(CreateOrderViewModel model)
        {
            var user = _userServices.GetUserByUsername(this.User.Identity.Name);

            var userId             = user.Id;
            var totalMoney         = 0.0m;
            var productIdForRecord = 0;
            var AddressDelivery    = "";
            var quantityForRecord  = 0;
            var paymentMethodRec   = "";

            var dayOfPurchase = DateTime.Now;

            var order = this._orderServices.GetProcessingOrder(this.User.Identity.Name);

            if (order == null)
            {
                order = this._orderServices.CreateOrder(this.User.Identity.Name);
            }

            decimal deliveryPrice = _suppliersService.GetDiliveryPrice(model.SupplierId, model.DeliveryType);

            this._orderServices.SetOrderDetails(order, model.FullName, model.PhoneNumber, model.PaymentType, model.DeliveryAddressId.Value, deliveryPrice);

            var adddress = _addressesServices.GetAllAddresses().Where(x => x.Id == order.DeliveryAddressId);

            var taxes = deliveryPrice;


            var typeOfPayment = order.PaymentType.ToString();

            paymentMethodRec = typeOfPayment;

            var productFromDb         = _productServices.GetProductById(model.ProductOrderViewModel.ProductId);
            var temporalEnterQuantity = productFromDb.Quantity - model.ProductOrderViewModel.ClientsQuantity;

            if (productFromDb.Quantity <= 1)
            {
                if (productFromDb.Quantity == 1)
                {
                    return(RedirectToAction("Error", "Orders"));
                }
            }
            if (temporalEnterQuantity <= 1 && productFromDb.Quantity > 1)
            {
                return(RedirectToAction("Create", "Orders", model.ProductOrderViewModel.ProductId));
            }

            StringBuilder sb = new StringBuilder();

            foreach (var address in adddress)
            {
                sb.Append("Град: " + address.City.Name.ToString() + " " + address.City.Postcode);
                sb.Append("Адрес: " + address.Street + " ");
                sb.Append("№ " + address.BuildingNumber + " ");
                sb.AppendLine("Допълнително описание: " + address.Description);
            }

            productIdForRecord = productFromDb.Id;
            AddressDelivery    = sb.ToString().Trim();

            if (temporalEnterQuantity > 0)
            {
                productFromDb.Quantity = temporalEnterQuantity;
                var priceWithAddTaxes = productFromDb.Price * 0.1M + productFromDb.Price;

                quantityForRecord = model.ProductOrderViewModel.ClientsQuantity;
                totalMoney        = model.ProductOrderViewModel.ClientsQuantity * priceWithAddTaxes;
            }

            _incomeMoneyService.Create(userId, totalMoney, productIdForRecord, quantityForRecord, paymentMethodRec, AddressDelivery, dayOfPurchase);

            this._db.Products.Update(productFromDb);
            this._db.SaveChanges();



            return(Redirect("/"));
        }