public async Task <IActionResult> Edit(int id, [Bind("FarmId,Name,Address,Town,County,ProvinceCode,PostalCode,HomePhone,CellPhone,Email,Directions,DateJoined,LastContactDate")] Farm farm)
        {
            if (id != farm.FarmId)
            {
                ModelState.AddModelError("", "The farm is for a different farmID than your asked for.");
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(farm);
                    await _context.SaveChangesAsync();

                    TempData["message"] = $"Farm updated: {farm.Name}";
                    return(RedirectToAction(nameof(Index)));
                }
                catch (Exception ex)
                {
                    while (ex.InnerException != null)
                    {
                        ex = ex.InnerException;
                    }
                    ModelState.AddModelError("", $"Exception occurred while updating farm: {ex.Message}.");
                }
            }

            await Edit(id);

            return(View(farm));
        }
        public async Task <IActionResult> Edit(string id, [Bind("ProvinceCode,Name,CountryCode")] Province province)
        {
            if (id != province.ProvinceCode)
            {
                ModelState.AddModelError("", "The province is for a different provinceID than your asked for.");;
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(province);
                    await _context.SaveChangesAsync();

                    TempData["message"] = $"Province updated: {province.Name}";
                    return(RedirectToAction(nameof(Index)));
                }
                catch (Exception ex)
                {
                    while (ex.InnerException != null)
                    {
                        ex = ex.InnerException;
                    }
                    ModelState.AddModelError("", $"Exception occurred while updating plot: {ex.Message}.");
                }
            }

            Create();
            return(View(province));
        }
Beispiel #3
0
        public async Task <IActionResult> Edit(int id, [Bind("VarietyId,CropId,Name")] Variety variety)
        {
            if (id != variety.VarietyId)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(variety);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!VarietyExists(variety.VarietyId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["CropId"]   = new SelectList(_context.Crop, "CropId", "CropId", variety.CropId);
            ViewData["cropName"] = HttpContext.Session.GetString("cropName");
            return(View(variety));
        }
        public async Task <IActionResult> Edit(int id, [Bind("VarietyId,CropId,Name")] Variety variety)
        {
            if (id != variety.VarietyId)
            {
                ModelState.AddModelError("", "The variety is for a different variety ID than your asked for.");
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(variety);
                    await _context.SaveChangesAsync();

                    TempData["message"] = $"Variety updated: {variety.Name}";
                    return(RedirectToAction(nameof(Index)));
                }
                catch (Exception ex)
                {
                    while (ex.InnerException != null)
                    {
                        ex = ex.InnerException;
                    }
                    ModelState.AddModelError("", $"exception updating album: {ex.Message}");
                }
            }

            Create();
            return(View(variety));
        }
        public async Task <IActionResult> Edit(string id, [Bind("ProvinceCode,Name,CountryCode,RetailTaxName,RetailTaxRate,FederalTaxIncluded")] Province province)
        {
            if (id != province.ProvinceCode)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(province);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!ProvinceExists(province.ProvinceCode))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            var countryName = _context.Country.AsQueryable();

            ViewData["CountryName"] = new SelectList(countryName.OrderBy(c => c.Name), "CountryCode", "Name");
            return(View(province));
        }
Beispiel #6
0
        public async Task <IActionResult> Edit(int id, [Bind("TreatmentId,Name,PlotId,Moisture,Yield,Weight")] Treatment treatment)
        {
            if (id != treatment.TreatmentId)
            {
                ModelState.AddModelError("", "The treatment is for a different treatmentID than your asked for.");
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(treatment);
                    await _context.SaveChangesAsync();

                    treatment.Name      = Request.Form["Name"];
                    TempData["message"] = $"Treatment updated: {treatment.Name}";
                    return(RedirectToAction(nameof(Index)));
                }
                catch (Exception ex)
                {
                    while (ex.InnerException != null)
                    {
                        ex = ex.InnerException;
                    }
                    ModelState.AddModelError("", $"Exception occurred while updating treatment: {ex.Message}.");
                }
            }

            return(View(treatment));
        }
Beispiel #7
0
        public async Task <IActionResult> Edit(int id, [Bind("TreatmentFertilizerId,TreatmentId,FertilizerName,RatePerAcre,RateMetric")] TreatmentFertilizer treatmentFertilizer)
        {
            if (id != treatmentFertilizer.TreatmentFertilizerId)
            {
                ModelState.AddModelError("", "The fertilizer for the treatment is for a different treatmentFertilizerID than your asked for.");
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(treatmentFertilizer);
                    await _context.SaveChangesAsync();

                    treatmentFertilizer.FertilizerName = Request.Form["FertilizerName"];
                    TempData["message"] = $"Fertilizer for treatment updated: {treatmentFertilizer.FertilizerName}";
                    return(RedirectToAction(nameof(Index)));
                }
                catch (Exception ex)
                {
                    while (ex.InnerException != null)
                    {
                        ex = ex.InnerException;
                    }
                    ModelState.AddModelError("", $"Exception occurred while updating fertilizer for treatment: {ex.Message}.");
                }
            }

            Create();
            return(View(treatmentFertilizer));
        }
        public async Task <IActionResult> Edit(string id, [Bind("ProvinceCode,Name,CountryCode,RetailTaxName,RetailTaxRate,FederalTaxIncluded")] Province province)
        {
            if (id != province.ProvinceCode)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(province);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!ProvinceExists(province.ProvinceCode))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(province));
        }
Beispiel #9
0
        public async Task <IActionResult> Edit(string id, [Bind("CountryCode,Name,PostalPattern,PhonePattern")] Country country)
        {
            if (id != country.CountryCode)
            {
                ModelState.AddModelError("", "The country is for a different countryID than your asked for.");
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(country);
                    await _context.SaveChangesAsync();

                    TempData["message"] = $"Country updated: {country.Name}";
                    return(RedirectToAction(nameof(Index)));
                }
                catch (Exception ex)
                {
                    while (ex.InnerException != null)
                    {
                        ex = ex.InnerException;
                    }
                    ModelState.AddModelError("", $"Exception occurred while updating plot: {ex.Message}.");
                }
            }

            Create();
            return(View(country));
        }
        public async Task <IActionResult> Edit(int id, [Bind("TreatmentId,Name,PlotId,Moisture,Yield,Weight")] Treatment treatment)
        {
            string currentFarmName = HttpContext.Session.GetString("FarmName");

            ViewBag.FarmName = currentFarmName;
            if (id != treatment.TreatmentId)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(treatment);
                    TempData["Message"] = $"Treatment for farm {currentFarmName} Updated successfully";

                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!TreatmentExists(treatment.TreatmentId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["PlotId"] = new SelectList(_context.Plot, "PlotId", "PlotId", treatment.PlotId);
            return(View(treatment));
        }
Beispiel #11
0
        public async Task <IActionResult> Edit(string id, [Bind("ProvinceCode,Name,CountryCode")] Province province)
        {
            if (id != province.ProvinceCode)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(province);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!ProvinceExists(province.ProvinceCode))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["CountryCode"] = new SelectList(_context.Country, "CountryCode", "CountryCode", province.CountryCode);
            ViewData["CountryName"] = new SelectList(_context.Country, "Name", "Name", province.CountryCode);

            return(View(province));
        }
Beispiel #12
0
        public async Task <IActionResult> Edit(int id, [Bind("CropId,Name,Image")] Crop crop)
        {
            if (id != crop.CropId)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(crop);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!CropExists(crop.CropId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(crop));
        }
Beispiel #13
0
        public async Task <IActionResult> Edit(string id, [Bind("CountryCode,Name,PostalPattern,PhonePattern,RetailTaxName,RetailTaxRate")] Country country)
        {
            if (id != country.CountryCode)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(country);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!CountryExists(country.CountryCode))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(country));
        }
        public async Task <IActionResult> Edit(int id, [Bind("PlotId,FarmId,VarietyId,DatePlanted,DateHarvested,PlantingRate,PlantingRateByPounds,RowWidth,PatternRepeats,OrganicMatter,BicarbP,Potassium,Magnesium,Calcium,PHsoil,PHbuffer,Cec,PercentBaseSaturationK,PercentBaseSaturationMg,PercentBaseSaturationCa,PercentBaseSaturationH,Comments")] Plot plot)
        {
            if (id != plot.PlotId)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(plot);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!PlotExists(plot.PlotId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            var farmContext    = _context.Farm.OrderBy(f => f.Name);
            var varietyContext = _context.Variety.OrderBy(v => v.Name);

            ViewData["FarmId"]    = new SelectList(farmContext, "FarmId", "Name", plot.FarmId);
            ViewData["VarietyId"] = new SelectList(varietyContext, "VarietyId", "Name", plot.VarietyId);
            return(View(plot));
        }
        public async Task <IActionResult> Edit(int id, [Bind("PlotId,FarmId,VarietyId,DatePlanted,DateHarvested,PlantingRate,PlantingRateByPounds,RowWidth,PatternRepeats,OrganicMatter,BicarbP,Potassium,Magnesium,Calcium,PHsoil,PHbuffer,Cec,PercentBaseSaturationK,PercentBaseSaturationMg,PercentBaseSaturationCa,PercentBaseSaturationH,Comments")] Plot plot)
        {
            if (id != plot.PlotId)
            {
                ModelState.AddModelError("", "The plot is for a different plotID than your asked for.");
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(plot);
                    await _context.SaveChangesAsync();

                    TempData["message"] = $"Plot updated: {plot.Farm}";
                    return(RedirectToAction(nameof(Index)));
                }
                catch (Exception ex)
                {
                    while (ex.InnerException != null)
                    {
                        ex = ex.InnerException;
                    }
                    ModelState.AddModelError("", $"Exception occurred while updating plot: {ex.Message}.");
                }
            }

            Create();
            return(View(plot));
        }
Beispiel #16
0
        public async Task <IActionResult> Edit(int id, [Bind("TreatmentFertilizerId,TreatmentId,FertilizerName,RatePerAcre,RateMetric")] TreatmentFertilizer treatmentFertilizer)
        {
            if (id != treatmentFertilizer.TreatmentFertilizerId)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(treatmentFertilizer);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!TreatmentFertilizerExists(treatmentFertilizer.TreatmentFertilizerId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["FertilizerName"] = new SelectList(_context.Fertilizer.OrderBy(f => f.FertilizerName), "FertilizerName", "FertilizerName", treatmentFertilizer.FertilizerName);
            ViewData["TreatmentId"]    = new SelectList(_context.Treatment, "TreatmentId", "TreatmentId", treatmentFertilizer.TreatmentId);

            return(View(treatmentFertilizer));
        }
Beispiel #17
0
        public async Task <IActionResult> Edit(int id, [Bind("TreatmentId,Name,PlotId,Moisture,Yield,Weight")] Treatment treatment)
        {
            if (id != treatment.TreatmentId)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(treatment);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!TreatmentExists(treatment.TreatmentId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["PlotId"] = new SelectList(_context.Plot, "PlotId", "PlotId", treatment.PlotId);
            return(View(treatment));
        }
Beispiel #18
0
        public async Task <IActionResult> Edit(string id, [Bind("ProvinceCode,Name,CountryCode")] Province province)
        {
            if (id != province.ProvinceCode)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    province.CountryCode = _context.Country.SingleOrDefault(c => c.Name == province.CountryCode).CountryCode;
                    _context.Update(province);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!ProvinceExists(province.ProvinceCode))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }

            string name = province.CountryCode = _context.Country.SingleOrDefault(p => p.CountryCode == province.CountryCode.ToString()).Name;

            ViewData["CountryName"] = new SelectList(_context.Country.OrderBy(x => x.Name), "Name", "Name", name);
            return(View(province));
        }
        public async Task <IActionResult> Edit(int id, [Bind("FarmId,Name,Address,Town,County,ProvinceCode,PostalCode,HomePhone,CellPhone,Email,Directions,DateJoined,LastContactDate")] Farm farm)
        {
            if (id != farm.FarmId)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(farm);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!FarmExists(farm.FarmId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["ProvinceCode"] = new SelectList(_context.Province, "ProvinceCode", "ProvinceCode", farm.ProvinceCode);
            return(View(farm));
        }
        public async Task <IActionResult> Edit(string id, [Bind("FertilizerName,Oecproduct,Liquid")] Fertilizer fertilizer)
        {
            if (id != fertilizer.FertilizerName)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(fertilizer);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!FertilizerExists(fertilizer.FertilizerName))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(fertilizer));
        }
Beispiel #21
0
        public async Task <IActionResult> Edit(int id, [Bind("FarmId,Name,Address,Town,County,ProvinceCode,PostalCode,HomePhone,CellPhone,Email,Directions,DateJoined,LastContactDate")] Farm farm)
        {
            if (id != farm.FarmId)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    TempData["Message"] = "Farm is successfully edited !";
                    _context.Update(farm);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException ex)
                {
                    if (!FarmExists(farm.FarmId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        ModelState.AddModelError("", $"error editing existing farm:{ex.GetBaseException().Message} ");
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["ProvinceCode"] = new SelectList(_context.Province.OrderBy(p => p.Name), "ProvinceCode", "Name", farm.ProvinceCode);
            return(View(farm));
        }
Beispiel #22
0
        public async Task <IActionResult> Edit(int id, [Bind("TreatmentId,Name,PlotId,Moisture,Yield,Weight")] Treatment treatment)
        {
            if (id != treatment.TreatmentId)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(treatment);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!TreatmentExists(treatment.TreatmentId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            int    plotId   = Convert.ToInt32(HttpContext.Session.GetString(nameof(plotId)));
            string plotName = HttpContext.Session.GetString(nameof(plotName));

            ViewData["FarmName"] = plotName;
            ViewData["PlotId"]   = plotId;
            return(View(treatment));
        }
Beispiel #23
0
        public async Task <IActionResult> Edit(int id, [Bind("FarmId,Name,Address,Town,County,ProvinceCode,PostalCode,HomePhone,CellPhone,Email,Directions,DateJoined,LastContactDate")] Farm farm)
        {
            try
            {
                if (id != farm.FarmId)
                {
                    return(NotFound());
                }

                if (ModelState.IsValid)
                {
                    try
                    {
                        //3d. if the insert works, place a msg in your temp data
                        //farm.ProvinceCode = _context.Province.SingleOrDefault(p => p.Name == farm.ProvinceCode.ToString()).ProvinceCode;
                        _context.Update(farm);
                        await _context.SaveChangesAsync();

                        TempData["message"] = "Farm edit was successful";
                    }
                    catch (DbUpdateConcurrencyException)
                    {
                        if (!FarmExists(farm.FarmId))
                        {
                            return(NotFound());
                        }
                        else
                        {
                            throw;
                        }
                    }
                    return(RedirectToAction(nameof(Index)));
                }
            }
            catch (Exception ex)
            {
                //3c
                //catch any exception that is thrown on Edit, place its innermost message into modelstate
                //and allow processing to continue to the said path
                //which should redisplay the users data with the error
                ModelState.AddModelError("", $"Error inserting edit: {ex.GetBaseException().Message}");
            }
            //3b.to display the province name, not code, in the drop down
            ViewData["ProvinceSelectList"] = new SelectList(_context.Province, "ProvinceCode", "Name", farm.ProvinceCode);
            return(View(farm));
        }
Beispiel #24
0
        public async Task <IActionResult> Edit(int id, [Bind("PlotId,FarmId,VarietyId,DatePlanted,Cec,PlantingRateByPounds")] Plot plot)
        {
            if (id != plot.PlotId)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(plot);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!PlotExists(plot.PlotId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                TempData["Message"] = "Yeehaw, Plot Number " + plot.PlotId.ToString() + " added";

                return(RedirectToAction(nameof(Index)));
            }

            int cropId;
            var variety = _context.Variety.AsQueryable();

            // sets variety to be items with previously persisted cropId
            if (HttpContext.Session.GetString(nameof(cropId)) != null)
            {
                cropId  = Convert.ToInt32(HttpContext.Session.GetString(nameof(cropId)));
                variety = variety.Where(a => a.CropId == cropId);
            }
            ViewData["FarmId"]    = new SelectList(_context.Farm.OrderBy(a => a.Name), "FarmId", "Name");
            ViewData["VarietyId"] = new SelectList(variety.OrderBy(a => a.Name), "VarietyId", "Name");
            TempData["Message"]   = "Awe Shoot, Plot Number " + plot.PlotId.ToString() + " didn't get added";
            return(View(plot));
        }
Beispiel #25
0
        public async Task <IActionResult> Edit(int id, [Bind("TreatmentFertilizerId,TreatmentId,FertilizerName,RatePerAcre,RateMetric")] TreatmentFertilizer treatmentFertilizer)
        {
            if (id != treatmentFertilizer.TreatmentFertilizerId)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    bool liquid = _context.Fertilizer.SingleOrDefault(f => f.FertilizerName.ToString() == treatmentFertilizer.FertilizerName).Liquid;

                    if (liquid == true)
                    {
                        treatmentFertilizer.RateMetric = "Gal";
                    }
                    else
                    {
                        treatmentFertilizer.RateMetric = "LB";
                    }

                    _context.Update(treatmentFertilizer);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!TreatmentFertilizerExists(treatmentFertilizer.TreatmentFertilizerId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["FertilizerName"] = new SelectList(_context.Fertilizer.OrderBy(f => f.FertilizerName), "FertilizerName", "FertilizerName", treatmentFertilizer.FertilizerName);
            ViewData["TreatmentId"]    = HttpContext.Session.GetString("treatementIdSession");
            return(View(treatmentFertilizer));
        }
        public async Task <IActionResult> Edit(int id, [Bind("TreatmentFertilizerId,TreatmentId,FertilizerName,RatePerAcre,RateMetric")] TreatmentFertilizer treatmentFertilizer)
        {
            var checkLiquid = _context.Fertilizer.FirstOrDefault(a => a.FertilizerName == treatmentFertilizer.FertilizerName && a.Liquid == true);

            if (checkLiquid != null)
            {
                treatmentFertilizer.RateMetric = "Gal";
            }
            else if (checkLiquid == null)
            {
                treatmentFertilizer.RateMetric = "LB";
            }

            if (id != treatmentFertilizer.TreatmentFertilizerId)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(treatmentFertilizer);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!TreatmentFertilizerExists(treatmentFertilizer.TreatmentFertilizerId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["FertilizerName"] = new SelectList(_context.Fertilizer, "FertilizerName", "FertilizerName", treatmentFertilizer.FertilizerName);
            ViewData["TreatmentId"]    = new SelectList(_context.Treatment, "TreatmentId", "TreatmentId", treatmentFertilizer.TreatmentId);
            return(View(treatmentFertilizer));
        }
Beispiel #27
0
 public async Task <IActionResult> Edit(int id, [Bind("FarmId,Name,Address,Town,County,ProvinceCode,PostalCode,HomePhone,CellPhone,Email,Directions,DateJoined,LastContactDate")] Farm farm)
 {
     if (id != farm.FarmId)
     {
         return(NotFound());
     }
     try
     {
         if (ModelState.IsValid)
         {
             TempData["Message"] = "New Farm is edited successfuly";
             _context.Update(farm);
             await _context.SaveChangesAsync();
         }
     }
     catch (Exception ex)
     {
         ModelState.AddModelError("", $"{ex.GetBaseException().Message}");
     }
     ViewData["ProvinceName"] = new SelectList(_context.Province, "ProvinceCode", "Name", farm.ProvinceCode);
     return(View(farm));
 }
        public async Task <IActionResult> Edit(int id, [Bind("TreatmentFertilizerId,TreatmentId,FertilizerName,RatePerAcre,RateMetric")] TreatmentFertilizer treatmentFertilizer)
        {
            var oECContext = _context.Fertilizer.AsQueryable();

            if (id != treatmentFertilizer.TreatmentFertilizerId)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    var myTreatmentFertilizer = treatmentFertilizer;
                    myTreatmentFertilizer.RateMetric = (oECContext
                                                        .FirstOrDefault(t => t.FertilizerName == myTreatmentFertilizer.FertilizerName)
                                                        .Liquid) ? "Gal" : "Lb";
                    _context.Update(treatmentFertilizer);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!TreatmentFertilizerExists(treatmentFertilizer.TreatmentFertilizerId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            int treatmentId = Convert.ToInt32(HttpContext.Session.GetString(nameof(treatmentId)));

            ViewData["FertilizerName"] = new SelectList(oECContext.OrderBy(a => a.FertilizerName), "FertilizerName", "FertilizerName", treatmentFertilizer.FertilizerName);
            ViewData["TreatmentId"]    = treatmentId;
            return(View(treatmentFertilizer));
        }
Beispiel #29
0
        public async Task <IActionResult> Edit(int id, [Bind("FarmId,Name,Address,Town,County,ProvinceCode,PostalCode,HomePhone,CellPhone,Email,Directions,DateJoined,LastContactDate")] Farm farm)
        {
            // to confirm this part
            if (id != farm.FarmId)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    //should just pass in the object instead of context
                    if (await TryUpdateModelAsync(farm))
                    {
                        _context.Update(farm);
                        TempData["message"] = "Update sucessfull";
                        await _context.SaveChangesAsync();
                    }
                }
                catch (DbUpdateConcurrencyException de)
                {
                    if (!FarmExists(farm.FarmId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        ModelState.AddModelError("", $"error updating farm information: {de.GetBaseException().Message}");
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            await Edit(id);

            ViewData["ProvinceCode"] = new SelectList(_context.Province.OrderBy(p => p.Name), "ProvinceCode", "Name", farm.ProvinceCode);
            return(View(farm));
        }
Beispiel #30
0
        public async Task <IActionResult> Edit(int id, [Bind("PlotId,FarmId,VarietyId,DatePlanted,DateHarvested,PlantingRate,PlantingRateByPounds,RowWidth,PatternRepeats,OrganicMatter,BicarbP,Potassium,Magnesium,Calcium,PHsoil,PHbuffer,Cec,PercentBaseSaturationK,PercentBaseSaturationMg,PercentBaseSaturationCa,PercentBaseSaturationH,Comments")] Plot plot)
        {
            if (id != plot.PlotId)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(plot);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!PlotExists(plot.PlotId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                if (HttpContext.Session.GetString("varietyId") != null)
                {
                    return(RedirectToAction(nameof(Index), new { varietyId = HttpContext.Session.GetString("varietyId"), varietyName = HttpContext.Session.GetString("varietyName") }));
                }
                else
                {
                    return(RedirectToAction(nameof(Index), new { cropId = HttpContext.Session.GetString("cropId"), cropName = HttpContext.Session.GetString("cropName") }));
                }
            }
            ViewData["FarmId"]    = new SelectList(_context.Farm, "FarmId", "Name", plot.FarmId);
            ViewData["VarietyId"] = new SelectList(_context.Variety, "VarietyId", "Name", plot.VarietyId);
            return(View(plot));
        }