Example #1
0
        // GET: MSPCropsDetails/Edit/5
        public async Task <IActionResult> Edit(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

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

            if (mSPCropsDetail == null)
            {
                return(NotFound());
            }
            var crop = new editmspcrop
            {
                ExistringImagePath       = mSPCropsDetail.Crops_image,
                Crops_name               = mSPCropsDetail.Crops_name,
                Crops_description        = mSPCropsDetail.Crops_description,
                Crops_price              = mSPCropsDetail.Crops_price,
                Crop_Buying_End_Date     = mSPCropsDetail.Crop_Buying_End_Date,
                Crop_Buying_Staring_Date = mSPCropsDetail.Crop_Buying_Staring_Date,
                MSPCrops_id              = mSPCropsDetail.MSPCrops_id,
            };

            return(View(crop));
        }
Example #2
0
        public string updateimage(editmspcrop editmspcrop)
        {
            string uniqname = null;

            if (editmspcrop.Crops_image != null)
            {
                string uplodeFolder = Path.Combine(hostEnvironment.WebRootPath, "CropImage");
                uniqname = Guid.NewGuid().ToString() + "_" + editmspcrop.Crops_image.FileName;
                string filepath = Path.Combine(uplodeFolder, uniqname);
                editmspcrop.Crops_image.CopyTo(new FileStream(filepath, FileMode.Create));
            }
            return(uniqname);
        }
Example #3
0
        public async Task <IActionResult> Edit(int id, editmspcrop editmspcrop)
        {
            if (id != editmspcrop.MSPCrops_id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    var curentcrop = await _context.MSPCropsDetails.Where(x => x.MSPCrops_id == id).FirstOrDefaultAsync();

                    curentcrop.Crops_description        = editmspcrop.Crops_description;
                    curentcrop.Crops_name               = editmspcrop.Crops_name;
                    curentcrop.Crops_price              = editmspcrop.Crops_price;
                    curentcrop.Crop_Buying_End_Date     = editmspcrop.Crop_Buying_End_Date;
                    curentcrop.Crop_Buying_Staring_Date = editmspcrop.Crop_Buying_Staring_Date;
                    if (editmspcrop.Crops_image != null)
                    {
                        string filepath = Path.Combine(hostEnvironment.WebRootPath,
                                                       "CropImage", editmspcrop.ExistringImagePath);
                        System.IO.File.Delete(filepath);
                        curentcrop.Crops_image = updateimage(editmspcrop);
                    }



                    _context.Update(curentcrop);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!MSPCropsDetailExists(editmspcrop.MSPCrops_id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(editmspcrop));
        }
Example #4
0
        // GET: MSPCropsDetails
        public async Task <IActionResult> Index()
        {
            var x = await _context.MSPCropsDetails.ToListAsync();

            var allmspcrop = new List <editmspcrop>();

            foreach (var y in x)
            {
                var crop = new editmspcrop
                {
                    Crops_description        = y.Crops_description,
                    ExistringImagePath       = y.Crops_image,
                    Crops_name               = y.Crops_name,
                    Crops_price              = y.Crops_price,
                    Crop_Buying_End_Date     = y.Crop_Buying_End_Date,
                    Crop_Buying_Staring_Date = y.Crop_Buying_Staring_Date,
                    MSPCrops_id              = y.MSPCrops_id,
                };
                allmspcrop.Add(crop);
            }
            return(View(allmspcrop));
        }