Beispiel #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"));
        }
Beispiel #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"));
            }
        }