コード例 #1
0
        public ActionResult CurrentMacros()
        {
            MacronutrientsModel model = null;

            if (Request.Cookies[_macroCookie] != null)
            {
                model = MacronutrientsModel.FromCookie(Request.Cookies[_macroCookie]);

                return(View(model));
            }

            return(View(model));
        }
コード例 #2
0
        public ActionResult Calculate(ClientInformationModel model)
        {
            // Validate Data

            // Read the old cookie so we can update if possible
            ClientInformationModel oldClientInfo = null;

            if (Request.Cookies[_clientInfoCookie] != null)
            {
                oldClientInfo = ClientInformationModel.FromCookie(Request.Cookies[_clientInfoCookie]);
            }

            MacronutrientsModel currentMacros = null;

            if (Request.Cookies[_macroCookie] != null)
            {
                currentMacros = MacronutrientsModel.FromCookie(Request.Cookies[_macroCookie]);
            }

            HttpCookie clientInfoCookie = ClientInformationModel.ToCookie(model);

            Response.AppendCookie(clientInfoCookie);

            MacronutrientsModel macros = null;

            if (oldClientInfo != null && currentMacros != null)
            {
                macros = MacronutrientsModel.Parse(Logic.MTL.UpdateMacros(currentMacros.ToMtlModel(), oldClientInfo.ToMtlModel(), model.ToMtlModel()));
            }
            else
            {
                macros = MacronutrientsModel.Parse(Logic.MTL.Calculate(model.ToMtlModel()));
            }

            HttpCookie currentMacrosCookie = MacronutrientsModel.ToCookie(macros);

            Response.AppendCookie(currentMacrosCookie);

            return(RedirectToAction("CurrentMacros"));
        }