public bool IsEx(float?puls)
        {
            using (var db = new SandmanEntities())
            {
                Astronauts      Astronaut = db.Astronauts.Find(AstronautSession);
                CurrentCalories Calorie   = db.CurrentCalories.Find(AstronautSession);

                if (puls >= (Astronaut.Pulse + Astronaut.Pulse * 0.7))
                {
                    Calorie.Calories = Calorie.Calories - CalEx("C");
                    db.SaveChanges();

                    return(true);
                }

                if (puls > (Astronaut.Pulse + Astronaut.Pulse * 0.5) && puls < (Astronaut.Pulse + Astronaut.Pulse * 0.7))
                {
                    Calorie.Calories = Calorie.Calories - CalEx("F");
                    db.SaveChanges();

                    return(true);
                }

                return(false);
            }
        }
        //UPDATE    (U in Crud)
        public int UpdateAstronaut(Astronauts astronaut)
        {
            db.Entry(astronaut).State = EntityState.Modified;
            db.SaveChanges();

            return(astronaut.AstronautId);
        }
        public async Task <IActionResult> Edit(int id, [Bind("Id,Name,Surname,BirthDate,Duty,CrewId,CountryId")] Astronauts astronauts)
        {
            if (id != astronauts.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    //CrewsAstronauts pair = _context.CrewsAstronauts.Where(ca => ca.AstronautId == astronauts.Id).FirstOrDefault();
                    //pair.CrewId = astronauts.CrewId;
                    //pair.Crew = _context.Crews.Where(c => c.Id == astronauts.CrewId).FirstOrDefault();
                    _context.Update(astronauts);
                    //_context.Update(pair);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!AstronautsExists(astronauts.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["CountryId"] = new SelectList(_context.Countires, "Id", "CountryName", astronauts.CountryId);
            return(View(astronauts));
        }
        //DELETE    (D in Crud)
        public int DeleteAstronaut(int id)
        {
            Astronauts astronaut = db.Astronauts.Find(id);

            db.Astronauts.Remove(astronaut);
            db.SaveChanges();
            return(id);
        }
        //CREATE   (C in Crud)
        public int AddAstronaut(Astronauts astronaut)
        {
            db.Astronauts.Add(astronaut);
            db.SaveChanges();

            int id = astronaut.AstronautId;

            return(id);
        }
Esempio n. 6
0
 /// <summary>
 /// Fonction qui va supprimer un Astronaute de la tâche
 /// </summary>
 /// <param name="astronaut">Astronaute à supprimmer</param>
 public void RemoveAstronaut(Astronaut astronaut)
 {
     try
     {
         Astronauts.Remove(astronaut);
         astronaut.Available = true;
     }
     catch
     { Console.WriteLine("{0} is not assigned to this task", astronaut.Name); }
 }
Esempio n. 7
0
 /// <summary>
 /// Fonction qui va ajouter un astronaute à la tâche
 /// </summary>
 /// <param name="astronaut">Astronaute à ajouter</param>
 public void AddAstronaut(Astronaut astronaut)
 {
     if (astronaut.Available == true)
     {
         Astronauts.Add(astronaut);
         astronaut.Available = false;
     }
     else
     {
         Console.WriteLine("This astronaut is not available");
     }
 }
        public bool IsSleep(float?puls)
        {
            using (var db = new SandmanEntities())
            {
                Astronauts Astronaut = db.Astronauts.Find(AstronautSession);

                if (puls <= (Astronaut.Pulse - Astronaut.Pulse * 0.08))
                {
                    SleepTime Sleep = db.SleepTime.Where(x => x.AstronautID == AstronautSession).OrderByDescending(x => x.SleepDown).First();

                    if (Sleep != null && Sleep.DayComplete == true)
                    {
                        SleepTime ST = new SleepTime();
                        ST.AstronautID = AstronautSession;
                        ST.SleepDown   = DateTime.Now;
                        ST.DayComplete = false;

                        db.SleepTime.Add(ST);
                        db.SaveChanges();

                        return(true);
                    }

                    return(true);
                }
                else
                {
                    var lista = (from a in db.SleepTime
                                 where a.AstronautID == AstronautSession && a.DayComplete == false
                                 select new
                    {
                        a.SleepTimeID
                    }).FirstOrDefault();

                    if (lista != null)
                    {
                        SleepTime act = db.SleepTime.Find(lista.SleepTimeID);
                        act.SleepUp     = DateTime.Now;
                        act.DayComplete = true;

                        db.SaveChanges();
                        return(false);
                    }
                }
                return(false);
            }
        }
        public async Task <IActionResult> Create(int crewId, [Bind("Id,Name,Surname,BirthDate,Duty,CrewId,CountryId")] Astronauts astronaut)
        {
            if (ModelState.IsValid)
            {
                CrewsAstronauts newPair = new CrewsAstronauts();
                newPair.CrewId      = crewId;
                newPair.AstronautId = astronaut.Id;
                newPair.Crew        = _context.Crews.Where(c => c.Id == crewId).FirstOrDefault();
                newPair.Astronaut   = astronaut;
                _context.Add(astronaut);
                _context.Add(newPair);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["CountryId"] = new SelectList(_context.Countires, "Id", "CountryName", astronaut.CountryId);
            return(View(astronaut));
        }
 public int Edit([FromBody] Astronauts astronaut)
 {
     return(astronautsDL.UpdateAstronaut(astronaut));
 }
 public int Create([FromBody] Astronauts astronaut)
 {
     return(astronautsDL.AddAstronaut(astronaut));
 }
        //READ      (R in Crud)
        public Astronauts GetAstronautDetail(int id)
        {
            Astronauts astronaut = db.Astronauts.Find(id);

            return(astronaut);
        }