示例#1
0
        public ActionResult AddProduct(ProductModel product)
        {
            AddressModel addressModel = new AddressModel() //first saving address due to forieng key
            {
                Id           = product.Id,
                AddressLine1 = product.Address.AddressLine1,
                AddressLine2 = product.Address.AddressLine2,
                City         = product.Address.City,
                State        = product.Address.State,
                Country      = product.Address.Country
            };
            var currentAddressId = iAddressRepo.SaveAddress(addressModel);        // address id of currently saving
            var currentAddress   = iAddressRepo.GetAddressByID(currentAddressId); // get current address

            ProductModel productModel = new ProductModel()
            {
                Id            = product.Id,
                Name          = product.Name,
                Brand         = product.Brand,
                ModelNo       = product.ModelNo,
                Category      = product.Category,
                Condition     = product.Condition,
                BuyNowPrice   = product.BuyNowPrice,
                BidDateTime   = product.BidDateTime,
                Quantity      = product.Quantity,
                ImagePath     = product.ImagePath,
                AddressId     = currentAddressId,
                AddedByUserId = product.AddedByUserId,
                BidPrice      = product.BidPrice,
                Address       = currentAddress
            };

            iProductRepo.SaveProduct(productModel); // new product save
            ViewBag.AddProductConfirmation = "Record added Succefully.";
            ModelState.Clear();                     // clear form data in view
            return(View());
        }