Exemplo n.º 1
0
        public async Task <ActionResult <String> > GetWaterIntakeByDate(String userId, DateTime date)
        {
            var usr = await userCollection.GetById(userId);

            if (usr == null)
            {
                return(NotFound());
            }

            foreach (var i in usr.WaterIntakeIds)
            {
                var ci = await waterIntakeCollection.GetById(i);

                if (ci == null)
                {
                    continue;
                }

                if (isSameDay(date, ci.Date))
                {
                    return(ci.Id.ToString());
                }
            }
            var ciNew = new WaterIntake(ObjectId.Empty, 0, ObjectId.Empty, date, 0);

            waterIntakeCollection.InsertOne(ciNew);
            await this.AddWaterIntakeToUser(userId, ciNew.Id.ToString());

            return(ciNew.Id.ToString());
        }
Exemplo n.º 2
0
        public async Task <ActionResult <WaterIntakeDto> > Add(WaterIntakeCreationDto item)
        {
            var na = new WaterIntake(ObjectId.Empty, item.GoWG, ObjectId.Empty, item.Date, item.GoWC);
            await waterIntakeCollection.InsertOneAsync(na);

            return(CreatedAtRoute(nameof(GetSingleWaterIntake), new { id = na.Id },
                                  new WaterIntakeDto(na.Id.ToString(), na.GoWG, na.GoWC, na.Date)));
        }
Exemplo n.º 3
0
        public void GivenIncreaseInIntake_TotalConsumedIncreasesByIntakeAmount()
        {
            var water = new WaterIntake();

            water.AddOuncesDrank(56);
            water.AddOuncesDrank(5);

            Assert.AreEqual(61, water.TotalConsumed);
        }
Exemplo n.º 4
0
        public void GivenIntakeReachesGoal_GoalReachedIsTrue()
        {
            WaterIntake water = new WaterIntake();

            water.AddOuncesDrank(Constants.WaterIntakeGoal);

            var goalReached = water.GoalReached;

            Assert.IsTrue(goalReached);
        }
Exemplo n.º 5
0
        public void CalculateOuncesRemaining()
        {
            WaterIntake water = new WaterIntake();

            water.AddOuncesDrank(11);
            water.AddOuncesDrank(5);

            IntakeStastics stats = water.ComputeStatistics();

            Assert.AreEqual(48, stats.OuncesRemaining);
        }
Exemplo n.º 6
0
        public async Task <ActionResult <WaterIntakeDto> > Replace(WaterIntakeDto item, string id)
        {
            var oldWaterIntake = await waterIntakeCollection.GetById(ObjectId.Parse(id));

            if (oldWaterIntake != null)
            {
                var na = new WaterIntake(ObjectId.Parse(id), item.GoWG, oldWaterIntake.ActivityId, item.Date, item.GoWC);
                await waterIntakeCollection.ReplaceById(id, na);
            }

            return(Ok(200));
        }
Exemplo n.º 7
0
        public void CalculateOuncesConsumed()
        {
            WaterIntake water = new WaterIntake();

            water.AddOuncesDrank(15);
            water.AddOuncesDrank(20);
            water.AddOuncesDrank(3);

            IntakeStastics stats = water.ComputeStatistics();

            Assert.AreEqual(38, stats.OuncesConsumed);
        }
Exemplo n.º 8
0
        public async Task <ActionResult <WaterIntakeDto> > InitWaterIntake()
        {
            var na = new WaterIntake(ObjectId.Empty, 7, ObjectId.Empty, DateTime.Now, 10);
            await waterIntakeCollection.InsertOneAsync(na);

            na = new WaterIntake(ObjectId.Empty, 14, ObjectId.Empty, DateTime.Now, 20);
            await waterIntakeCollection.InsertOneAsync(na);

            na = new WaterIntake(ObjectId.Empty, 17, ObjectId.Empty, DateTime.Now, 18);
            await waterIntakeCollection.InsertOneAsync(na);

            return(Ok(200));
        }
Exemplo n.º 9
0
        public void PrintWaterIntakeSoFarMessage()
        {
            WaterIntake water = new WaterIntake();

            water.AddOuncesDrank(25);
            water.AddOuncesDrank(20);

            var stats = water.ComputeStatistics();

            var message = water.DisplayMessage(stats);

            Assert.AreEqual("You have consumed 45 ounce(s) of water today.", message.WaterIntakeSoFarMessage);
        }
Exemplo n.º 10
0
        public ActionResult DeleteWaterIntake(int?id)
        {
            if (id == null)
            {
                return(HttpNotFound());
            }
            WaterIntake wt = db.WaterIntakes.Find(id);

            if (wt == null)
            {
                return(HttpNotFound());
            }
            return(View(wt));
        }
Exemplo n.º 11
0
        private WaterIntake WaterIntakeModelToWaterIntakeMap(WaterIntakeModel wtmodel)
        {
            WaterIntake wt = new WaterIntake()
            {
                Id             = 100,
                LaboratoryId   = wtmodel.LaboratoryId,
                IntakeDate     = wtmodel.IntakeDate,
                LaboratoryDate = wtmodel.LaboratoryDate,
                WorkerName     = wtmodel.WorkerName,
                StationId      = wtmodel.StationId
            };

            return(wt);
        }
Exemplo n.º 12
0
        public ActionResult EditWaterIntake(int?id)
        {
            if (id == null)
            {
                return(HttpNotFound());
            }
            WaterIntake wt = db.WaterIntakes.Find(id);

            if (wt == null)
            {
                return(HttpNotFound());
            }

            Chemical     ch = wt.Chemical;
            Organoleptic or = wt.Organoleptic;

            WaterIntakeModel wtmodel = new WaterIntakeModel()
            {
                Id             = wt.Id,
                LaboratoryId   = wt.LaboratoryId,
                IntakeDate     = wt.IntakeDate,
                LaboratoryDate = wt.LaboratoryDate,
                WorkerName     = wt.WorkerName,
                StationId      = wt.StationId,
                Status         = wt.Status,

                Residue   = ch.Residue,
                Ph        = ch.Ph,
                Rigidity  = ch.Rigidity,
                Chlorides = ch.Chlorides,
                Sulphates = ch.Sulphates,
                Iron      = ch.Iron,
                Marhan    = ch.Marhan,
                Fluorine  = ch.Fluorine,
                Nitrates  = ch.Nitrates,


                Scent20      = or.Scent20,
                Scent60      = or.Scent60,
                Flavor       = or.Flavor,
                Chromaticity = or.Chromaticity,
                Turbidity    = or.Turbidity,
                Temperature  = or.Temperature
            };

            WaterIntakeViewBag();
            return(View(wtmodel));
        }
        public async Task <ActionResult <Boolean> > AddActivityToWaterIntake(String waterIntakeId, String activityId)
        {
            var waterIntake = await waterIntakeCollection.GetById(waterIntakeId);

            if (waterIntake == null)
            {
                return(NotFound(false));
            }

            await waterIntakeCollection.DeleteById(waterIntake.Id);

            var na = new WaterIntake(waterIntake.Id, waterIntake.GoWG, ObjectId.Parse(activityId), waterIntake.Date, waterIntake.GoWC);

            await waterIntakeCollection.InsertOneAsync(na);

            return(Ok(true));
        }
Exemplo n.º 14
0
        public ActionResult DeleteWaterIntakeConfirmed(int?id)
        {
            if (id == null)
            {
                return(HttpNotFound());
            }
            WaterIntake wt = db.WaterIntakes.Find(id);

            if (wt == null)
            {
                return(HttpNotFound());
            }

            Organoleptic or = db.Organoleptics.Find(id);
            Chemical     ch = db.Chemicals.Find(id);

            db.Organoleptics.Remove(or);
            db.Chemicals.Remove(ch);
            db.WaterIntakes.Remove(wt);
            db.SaveChanges();
            return(RedirectToAction("WaterIntakes"));
        }
Exemplo n.º 15
0
        public ActionResult EditWaterIntake(WaterIntakeModel wtmodel)
        {
            if (ModelState.IsValid)
            {
                WaterIntake wt = new WaterIntake()
                {
                    Id             = wtmodel.Id,
                    LaboratoryId   = wtmodel.LaboratoryId,
                    IntakeDate     = wtmodel.IntakeDate,
                    LaboratoryDate = wtmodel.LaboratoryDate,
                    WorkerName     = wtmodel.WorkerName,
                    StationId      = wtmodel.StationId,
                };
                Chemical ch = new Chemical()
                {
                    Id        = wtmodel.Id,
                    Residue   = wtmodel.Residue,
                    Ph        = wtmodel.Ph,
                    Rigidity  = wtmodel.Rigidity,
                    Chlorides = wtmodel.Chlorides,
                    Sulphates = wtmodel.Sulphates,
                    Iron      = wtmodel.Iron,
                    Marhan    = wtmodel.Marhan,
                    Fluorine  = wtmodel.Fluorine,
                    Nitrates  = wtmodel.Nitrates
                };
                Organoleptic or = new Organoleptic()
                {
                    Id           = wtmodel.Id,
                    Scent20      = wtmodel.Scent20,
                    Scent60      = wtmodel.Scent60,
                    Flavor       = wtmodel.Flavor,
                    Chromaticity = wtmodel.Chromaticity,
                    Turbidity    = wtmodel.Turbidity,
                    Temperature  = wtmodel.Temperature
                };

                if (wtmodel.LaboratoryDate == null)
                {
                    wt.Status = DAL.Status.taken;
                }
                else
                {
                    wt.Status = DAL.Status.investigated;
                }

                db.Entry(wt).State = EntityState.Modified;
                db.Entry(ch).State = EntityState.Modified;
                db.Entry(or).State = EntityState.Modified;
                var     k = db.WaterIntakes.OrderByDescending(a => a.Id).First();
                Station s = db.Stations.Find(wtmodel.StationId);
                if (wtmodel.Id == k.Id)
                {
                    s.Class = CheckingClass(ch, or);
                }
                db.Entry(s).State = EntityState.Modified;
                db.SaveChanges();
                return(RedirectToAction("WaterIntakes"));
            }

            WaterIntakeViewBag();
            return(View(wtmodel));
        }
Exemplo n.º 16
0
        public ActionResult CreateWaterIntake(WaterIntakeModel wtmodel)
        {
            Laboratory b = db.Laboratories.Find(wtmodel.LaboratoryId);
            Station    s = db.Stations.Find(wtmodel.StationId);

            if (b == null)
            {
                throw new OperationCanceledException("Laboratory not found");
            }

            if (s == null)
            {
                throw new OperationCanceledException("Station not found");
            }

            WaterIntake wt = WaterIntakeModelToWaterIntakeMap(wtmodel);

            wt.Laboratory = b;
            wt.Station    = s;

            Chemical     ch = WaterIntakeModelToChemical(wtmodel);
            Organoleptic or = WaterIntakeModelToOrganoleptic(wtmodel);

            if (ModelState.IsValid)
            {
                if (wtmodel.LaboratoryDate == null)
                {
                    wt.Status = DAL.Status.taken;
                }
                else
                {
                    wt.Status = DAL.Status.investigated;
                }

                s.Class = CheckingClass(ch, or);

                db.WaterIntakes.Add(wt);
                db.Chemicals.Add(ch);
                db.Organoleptics.Add(or);
                db.SaveChanges();

                return(RedirectToAction("WaterIntakes"));
            }
            else
            {
                WaterIntakeViewBag();

                if (wtmodel.IntakeDate == default(DateTime))
                {
                    ViewBag.IntakeDate = DateTime.Now;
                }
                else
                {
                    ViewBag.IntakeDate = wtmodel.IntakeDate;
                }

                if (wtmodel.LaboratoryDate == default(DateTime))
                {
                    ViewBag.LaboratoryDate = DateTime.Now;
                }
                else
                {
                    ViewBag.LaboratoryDate = wtmodel.LaboratoryDate;
                }

                return(View(wtmodel));
            }
        }