Пример #1
0
        public async Task <IActionResult> SellCropInMSP(int?id, MSPSellCrops mSPSellCrops)
        {
            if (mSPSellCrops.Crops_quantity == 0)
            {
                ModelState.AddModelError(string.Empty, "Invalid Crop Quentity");
                return(View(mSPSellCrops));
            }
            if (mSPSellCrops.Farmers.Farmers_address == null)
            {
                ModelState.AddModelError(string.Empty, "Address is Required Field");
                return(View(mSPSellCrops));
            }
            if (id == null || id == 0)
            {
                return(NotFound());
            }
            var mSPCropsDetail = await _context.MSPCropsDetails.FindAsync(id);


            var curentuser = await _context.Farmers.Where(x => x.Farmers_email == User.Identity.Name).FirstOrDefaultAsync();

            if (mSPCropsDetail == null || curentuser == null)
            {
                return(NotFound());
            }
            curentuser.Farmers_address = mSPSellCrops.Farmers.Farmers_address;
            _context.Update(curentuser);
            var sellcrop = new MSPSellCrops
            {
                Crops_quantity = mSPSellCrops.Crops_quantity,
                MSPCrops_id    = mSPCropsDetail.MSPCrops_id,
                Farmers_id     = curentuser.Farmers_id,
            };

            _context.Add(sellcrop);
            await _context.SaveChangesAsync();

            return(RedirectToAction("sellinmsp", "Farmers"));
        }
Пример #2
0
        public async Task <IActionResult> SellCropInMSP(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            var mSPCropsDetail = await _context.MSPCropsDetails.FindAsync(id);

            var farmerdetail = await _context.Farmers.Where(x => x.Farmers_email == User.Identity.Name).FirstOrDefaultAsync();

            if (mSPCropsDetail == null || farmerdetail == null)
            {
                return(NotFound());
            }
            var mspsellcrop = new MSPSellCrops
            {
                MSPCropsDetail = mSPCropsDetail,
                Farmers        = farmerdetail,
            };

            return(View(mspsellcrop));
        }