示例#1
0
        public ActionResult Setup(SetupModel model)
        {
            if (model == null)
            {
                ViewBag.Records = "Something went wrong. Please try again.";
                return(RedirectToAction("Index", "Home"));
            }

            using (var db = new ginoEntities1())
            {
                userpref dd = new userpref();
                db.userprefs.Add(dd);

                dd.addictiontype  = model.AddictionType;
                dd.cost           = model.Costperday;
                dd.units          = model.Nmbrperday;
                dd.userId         = model.UserId;
                dd.stopDate       = DateTime.UtcNow;
                dd.Deleted        = false;
                dd.sharing        = true;
                dd.substituteUser = model.UsingSubstitute;

                //dd.addictionproducttype = model.ProductPost;
                //Hårdkodat produktval tills väljare funkar bra.
                if (model.AddictionType == 1)
                {
                    dd.addictionproducttype = 1;
                }
                else if (model.AddictionType == 2)
                {
                    dd.addictionproducttype = 2;
                }

                db.SaveChanges();

                if (model.UsingSubstitute == true)
                {
                    substitute s = new substitute();
                    db.substitutes.Add(s);

                    s.amount     = model.Substituteamount;
                    s.unit       = "mg";
                    s.deleted    = false;
                    s.updated    = DateTime.UtcNow;
                    s.userprefId = dd.Id;
                    db.SaveChanges();
                }
            }

            return(RedirectToAction("Index", "User"));
        }
示例#2
0
        public ActionResult Settings(UserModel model)
        {
            if (Request.Form["updateSettings"] != null)
            {
                using (var db = new ginoEntities1())
                {
                    var updatebool = db.userprefs.FirstOrDefault(x => x.Id == model.userprefId);
                    if (updatebool == null)
                    {
                    }
                    updatebool.substituteUser = model.isUsingSubstitute;

                    if (model.isUsingSubstitute == true)
                    {
                        substitute dd = new substitute();
                        db.substitutes.Add(dd);

                        dd.updated    = DateTime.UtcNow;
                        dd.unit       = "mg";
                        dd.amount     = model.Substituteamount;
                        dd.userprefId = model.userprefId;
                        dd.deleted    = false;
                    }

                    db.SaveChanges();
                }
                return(RedirectToAction("Settings", "User"));
            }
            else if (Request.Form["stopCounter"] != null)
            {
                using (var db = new ginoEntities1())
                {
                    var stopCounting = db.userprefs.FirstOrDefault(x => x.Id == model.userprefId);
                    if (stopCounting == null)
                    {
                        return(this.HttpNotFound("Something went wrong. Please try again."));
                    }

                    stopCounting.Deleted    = true;
                    stopCounting.deleteDate = DateTime.UtcNow;

                    db.SaveChanges();
                }
                return(RedirectToAction("Setup", "User"));
            }
            else
            {
                return(RedirectToAction("Settings", "User"));
            }
        }
示例#3
0
        public PartialViewResult Index(int userprefid, string moodbutton, UserModel model)

        {
            int mood = 1337;

            if (moodbutton == "minustwo")
            {
                mood = -2;
            }
            else if (moodbutton == "minusone")
            {
                mood = -1;
            }
            else if (moodbutton == "zero")
            {
                mood = 0;
            }
            else if (moodbutton == "plusone")
            {
                mood = 1;
            }
            else if (moodbutton == "plustwo")
            {
                mood = 2;
            }

            using (var db = new ginoEntities1())
            {
                mood dd = new mood();
                db.moods.Add(dd);

                dd.Mood1      = mood;
                dd.TS         = DateTime.UtcNow;
                dd.userprefid = userprefid;
                db.SaveChanges();
            }

            ViewBag.Records = "Your mood has been stored. Keep it up!";

            bool SubstituteResult;
            int  CounterId = 0;

            GetCounterId(User.Identity.GetUserId(), out SubstituteResult, out CounterId);
            model.userprefId = CounterId;

            return(PartialView("_MoodPartial", model));
        }
示例#4
0
        public PartialViewResult addMg(string moodbutton, int substituteId, UserModel model)

        {
            using (var db = new ginoEntities1())
            {
                substitutestat st = new substitutestat();
                db.substitutestats.Add(st);

                st.substituteId = substituteId;
                st.TS           = DateTime.UtcNow;
                db.SaveChanges();
            };

            bool SubstituteResult;
            int  CounterId = 0;

            GetCounterId(User.Identity.GetUserId(), out SubstituteResult, out CounterId);

            //HARDCODE, CHANGE LATER
            if (SubstituteResult == true)
            {
                using (var db = new ginoEntities1())
                {
                    model.isUsingSubstitute = true;

                    var substituteIdQuery = (from s in db.substitutes
                                             where s.deleted == false && s.userprefId == CounterId
                                             orderby s.updated descending
                                             select new { s.Id }).FirstOrDefault();

                    model.substituteId = substituteIdQuery.Id;

                    //get total nicotine per day
                    var nicPerDayQuery = (from n in db.nicotine_per_day
                                          where n.userprefid == CounterId
                                          select new { n.nic_per_day }
                                          ).FirstOrDefault();

                    //get today's substitute-nicotine
                    var substitute = (from s in db.substitute_nicotine_today
                                      where s.userprefid == CounterId
                                      select new { s.today_amount }).FirstOrDefault();

                    if (substitute != null)
                    {
                        var badamount = (substitute.today_amount / nicPerDayQuery.nic_per_day);

                        if (badamount.Value > 0.3M)
                        {
                            model.substituteMood = "#ecaa93";
                        }
                        else if (badamount.Value > 0.2M)
                        {
                            model.substituteMood = "#f3c8b9";
                        }
                        else if (badamount.Value > 0.05M)
                        {
                            model.substituteMood = "#faf5e5";
                        }
                        else if (badamount.Value > 0.02M)
                        {
                            model.substituteMood = "#b9f3c8";
                        }
                        else
                        {
                            model.substituteMood = "#93ecaa";
                        }
                        model.substituteDayAmount = substitute.today_amount ?? 0;
                    }
                    else
                    {
                        model.substituteMood      = "#93ecaa";
                        model.substituteDayAmount = 0;
                    }
                }
            }


            //DEtta borde inte vara här

            return(PartialView("_SubstitutePartial", model));
        }
示例#5
0
        public ActionResult A6628f749b17c4e5b832c354e5b0ea22d()
        {
            //if (User.Identity.Name == "*****@*****.**")
            //{

            using (var db = new ginoEntities1())
            {
                var prefs = (from p in db.userprefs
                             where p.Deleted == false
                             select new { p.Id, p.stopDate }).ToArray();

                if (prefs != null)
                {
                    foreach (var Id in prefs)
                    {
                        var now    = DateTime.UtcNow;
                        var stop   = Id.stopDate;
                        var length = (now - stop).Value.TotalDays;
                        int level  = 0;

                        if (length > 364)
                        {
                            level = 6;
                        }
                        else if (length > (365 / 2))
                        {
                            level = 5;
                        }
                        else if (length > 99)
                        {
                            level = 4;
                        }
                        else if (length > 31)
                        {
                            level = 3;
                        }
                        else if (length > 6)
                        {
                            level = 2;
                        }
                        else if (length > 1)
                        {
                            level = 1;
                        }

                        var maxlevel = (from ua in db.userachivements
                                        where ua.userprefid == Id.Id && ua.deleted == false && ua.achivementtype == 2
                                        orderby ua.achivementid descending
                                        select ua.achivementid).Take(1).SingleOrDefault().ToString();

                        var maxlevelint = 0;
                        maxlevelint = Int32.Parse(maxlevel);


                        if (level > maxlevelint)
                        {
                            for (int n = 1; n <= level; n++)
                            {
                                userachivement uas = new userachivement();
                                db.userachivements.Add(uas);
                                uas.deleted        = false;
                                uas.TS             = DateTime.UtcNow;
                                uas.userprefid     = Id.Id;
                                uas.achivementtype = 2;
                                //uas.achivementid = level;
                                uas.achivementid = n;
                                db.SaveChanges();
                            }
                        }
                    }
                }
            }

            return(View());
            //}
            //else
            //{
            //    return RedirectToAction("Index", "Home");
            //}
        }