Exemple #1
0
        // GET: Species/Edit/5
        public ActionResult Edit(long?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Specie s = db.Species.Find(id);

            if (s == null)
            {
                return(HttpNotFound());
            }
            SpecieViewModel vm = new SpecieViewModel();

            vm.SpecieId          = s.SpecieId;
            vm.ShortName         = s.ShortName;
            vm.BaseTemperature   = s.BaseTemperature;
            vm.StressTemperature = s.StressTemperature;
            vm.SpecieType        = s.SpecieType;
            vm.RegionId          = s.RegionId;
            vm.SpecieCycleId     = s.SpecieCycleId;

            vm.Regions      = this.LoadRegion(s.RegionId, s);
            vm.SpecieCycles = this.LoadSpecieCycles(s.SpecieCycleId, s);
            return(View("~/Views/Agriculture/Species/Edit.cshtml", vm));
        }
Exemple #2
0
        // GET: Species/Create
        public ActionResult Create()
        {
            SpecieViewModel vm = new SpecieViewModel();

            vm.Regions      = this.LoadRegion();
            vm.SpecieCycles = this.LoadSpecieCycles();
            return(View("~/Views/Agriculture/Species/Create.cshtml", vm));
        }
 public static Specie Map(SpecieViewModel model, bool valMutant = false)
 {
     return(new Specie()
     {
         adn = model.adn,
         mutant = valMutant,
     });
 }
 public async Task <IActionResult> mutant([FromBody] SpecieViewModel especieModel)
 {
     if (await _specieService.IsMutant(especieModel.adn))
     {
         return(Ok());
     }
     else
     {
         return(new StatusCodeResult(Convert.ToInt32(403)));
         //Response.StatusCode = 403;
         //HttpContext.Response.StatusCode = 403;
         //return BadRequest();
     }
     //return BadRequest(;
 }
Exemple #5
0
        public ActionResult Create([Bind(Include = "SpecieId,ShortName,SpecieCycleId,BaseTemperature,StressTemperature,RegionId, SpecieType")] SpecieViewModel svm)
        {
            if (ModelState.IsValid)
            {
                SpecieCycle specieCycle = db.SpecieCycles.Find(svm.SpecieCycleId);
                Specie      specie      = new Specie();
                specie.Name              = svm.ShortName + " " + specieCycle.Name;
                specie.SpecieCycleId     = svm.SpecieCycleId;
                specie.ShortName         = svm.ShortName;
                specie.BaseTemperature   = svm.BaseTemperature;
                specie.StressTemperature = svm.StressTemperature;
                specie.RegionId          = svm.RegionId;
                specie.SpecieType        = svm.SpecieType;

                db.Species.Add(specie);
                db.SaveChanges();
            }
            return(Redirect("/Species"));
        }
        public async Task <DataResult <SpecieViewModel> > GetSpecieViewById(int id)
        {
            try
            {
                SpecieViewModel model = await _specieRepository.GetModelById(id);

                return(new DataResult <SpecieViewModel>
                {
                    Success = true,
                    Data = model,
                });
            }
            catch (Exception ex)
            {
                _logger.LogError(ex, $"Problems with getting Specie by id : {id}");
                return(new DataResult <SpecieViewModel>
                {
                    Success = false,
                    ErrorCode = ErrorCode.InternalError,
                });
            }
        }
Exemple #7
0
        public ActionResult Edit([Bind(Include = "SpecieId,ShortName,SpecieCycleId,BaseTemperature,StressTemperature, RegionId, ")] SpecieViewModel svm)
        {
            if (ModelState.IsValid)
            {
                SpecieCycle specieCycle = db.SpecieCycles.Find(svm.SpecieCycleId);

                Specie updatedSpecie = db.Species.Find(svm.SpecieId);
                if (updatedSpecie == null)
                {
                    return(HttpNotFound());
                }
                updatedSpecie.Name              = svm.ShortName + " " + specieCycle.Name;
                updatedSpecie.ShortName         = svm.ShortName;
                updatedSpecie.BaseTemperature   = svm.BaseTemperature;
                updatedSpecie.StressTemperature = svm.StressTemperature;
                updatedSpecie.SpecieCycleId     = svm.SpecieCycleId;
                updatedSpecie.RegionId          = svm.RegionId;
                updatedSpecie.SpecieType        = svm.SpecieType;

                db.Entry(updatedSpecie).State = EntityState.Modified;
                db.SaveChanges();
            }
            return(Redirect("/Species"));
        }