/// <summary>
        /// Gets the information of a new single promotion and send it to the database.
        /// </summary>
        /// <returns></returns>
        public ActionResult NewSinglePromotion()
        {
            AdminModel AdminModel = (AdminModel)TempData["admin"];

            // get the type of material
            string materialType = Request["materialType"].ToString();

            // get the amount of kg of the material
            int amountKg = int.Parse(Request["inputAmountKg"].ToString());

            // get the value of tcs of the promotion
            float valueTCS = float.Parse(Request["inputValueTCS"].ToString());

            // get the datetime of the promotion
            string finishDate = Request["inputFinishDate"].ToString();

            // value of the active state of the promotion: 1=active, 0=notactive; by default is 0
            int activeValue = 0;

            // if the user wants the promotion to be active and publish now, else not
            if (Request["publish"] != null && Request["save"] == null)
            {
                activeValue = 1;
            }

            // if the user let one option blank is shown a message
            if (Request["publish"] == null && Request["save"] == null)
            {
                ViewBag.Msj = "Se debe seleccionar si desea Activar o Almacenar.";
            }

            // if the user wants the promotion to be save and ketp for later
            if (Request["publicar"] == null && Request["almacenar"] != null)
            {
                activeValue = 0;
            }

            // send the information to the database
            DBConnection.InsertNewPromotion(AdminModel.Id, valueTCS, finishDate, activeValue, 1);
            DBConnection.GetNewestIdPromotion(AdminModel.PromotionModel);
            int IdPromotion = AdminModel.PromotionModel.LatestIdPromotion;

            DBConnection.InsertPromosMaterial(IdPromotion, materialType, amountKg);

            // if the promotion is active, make it a tweet
            if (activeValue == 1)
            {
                TwitterConnection.SetCredentials();
                TwitterConnection.Publish(
                    "Hay una nueva promocion de: " + valueTCS + " TEColones. Consiste en entregar: " +
                    amountKg + " kg de " + materialType + ". La promocion es valida hasta: " + finishDate
                    );
            }
            return(View("~/Views/Administrator/Promotion/CreateSinglePromotion.cshtml", AdminModel));
        }
        public ActionResult GetNewMaterialTCSValues()
        {
            AdminModel AdminModel = (AdminModel)TempData["admin"];

            TwitterConnection.SetCredentials();
            foreach (KeyValuePair <string, float> item in AdminModel.ConfigurationModel.Materials)
            {
                string newValue = Request[item.Key];
                if (!string.IsNullOrWhiteSpace(newValue))
                {
                    string name = item.Key;
                    DBConnection.InsertNewMaterialTCSValue(name, float.Parse(newValue));
                    string message = String.Format("La tasa de cambio del material {0} por kg es: {1} TEColones", name, newValue);
                    TwitterConnection.Publish(message);
                }
            }
            DBConnection.GetMaterialTCSValue(AdminModel.ConfigurationModel);
            return(View("~/Views/Administrator/Configuration/MaterialConfig.cshtml", AdminModel));
        }
Пример #3
0
        public ActionResult Register() //(SCMModel emple)
        {
            SCM scm = (SCM)TempData["scm"];

            IDictionary <string, string> dict = new Dictionary <string, string>();

            foreach (string material in scm.Materials)
            {
                dict.Add(material, Request[material].ToString());
            }
            string carnet = Request["InputCarnet"].ToString();

            if (DBConnection.ExistUser(carnet).Equals(1))
            {
                string email         = DBConnection.GetEmailUser(carnet);
                string messageToSend = String.Format("El estudiante {0} ha ingresado ", carnet);

                foreach (KeyValuePair <string, string> item in dict)
                {
                    if (!string.IsNullOrWhiteSpace(item.Value))
                    {
                        //if (DBConnection.VerifyPromotion()){} --> APLICAR PROMOCION

                        DBConnection.InsertRegister(carnet, scm.Id, item.Key, item.Value);
                        messageToSend += String.Format("{0} kg del material {1}. ", item.Value, item.Key);
                    }
                }

                TwitterConnection.SetCredentials();
                TwitterConnection.Publish(messageToSend);

                SendEmail(email, messageToSend);

                ViewBag.Message = String.Format("Se registro el material con exito, para el estudiante {0}", carnet);
                return(PartialView("~/Views/StorageCenterManager/SCMHome/SCMHome.cshtml", scm));
            }
            else
            {
                ViewBag.Message = String.Format("Numero {0} no existe como Usuario Estudiante", carnet);
                return(PartialView("~/Views/StorageCenterManager/SCMHome/SCMHome.cshtml", scm));
            }
        }
        public ActionResult GetNewBenefitsValues()
        {
            AdminModel AdminModel         = (AdminModel)TempData["admin"];
            string     NewStudyExchange   = Request["inputTCSStudy"];
            string     NewDinningExchange = Request["inputTCSDinning"];

            TwitterConnection.SetCredentials();
            if (!string.IsNullOrWhiteSpace(NewStudyExchange))
            {
                DBConnection.InsertNewBenefitsValue(float.Parse(NewStudyExchange), "Matricula");
                TwitterConnection.Publish("La tasa de cambio de TEColones en los Derechos de Estudio (Matricula) es: " + NewStudyExchange + " colones");
            }
            if (!string.IsNullOrWhiteSpace(NewDinningExchange))
            {
                DBConnection.InsertNewBenefitsValue(float.Parse(NewDinningExchange), "Comedor");
                TwitterConnection.Publish("La tasa de cambio de TEColones en el Comedor Intitucional es: " + NewDinningExchange + " colones");
            }

            DBConnection.GetBenefitsValue(AdminModel.ConfigurationModel);
            return(View("~/Views/Administrator/Configuration/TEColonesConfig.cshtml", AdminModel));
        }
        /// <summary>
        /// Gets the information of a new combo promotion and send it to the database.
        /// </summary>
        /// <returns></returns>
        public ActionResult NewComboPromotion()
        {
            AdminModel AdminModel = (AdminModel)TempData["admin"];

            Dictionary <string, int> dict = new Dictionary <string, int>();

            // checks the value of the inputs: name, amount of kg, the checkbox
            foreach (var item in AdminModel.PromotionModel.ListMaterials)
            {
                string materialType = item;                        // which type of material is, the name of the material
                string amountKg     = Request[item];               // the amount, float, of kg of the material
                string checkBox     = Request["checkbox " + item]; // the value of the checkbox

                if (amountKg != " " && checkBox != null)
                {
                    int amountKgInt = int.Parse(amountKg); // converts the string type of amount to float for the sending it to the database
                    dict.Add(materialType, amountKgInt);
                }
                else
                {
                    continue;
                }
            }

            // to be a combo at least must be two materials, else proceed to choose again.
            if (dict.Count < 2)
            {
                ViewBag.Msj = "Para crear una PromocionCombo minimo son dos materiales. Si desea solo un material, proceda a la seccion de Promo Individual.";
            }

            // checks and gets the value of the tcs and the datetime of it
            float  valueTCS   = float.Parse(Request["inputValueTCS"]);
            string finishDate = Request["inputFinishDate"].ToString();

            // value of the active state of the promotion: 1=active, 0=notactive; by default is 0
            int activeValue = 0;

            // if the user wants the promotion to be active and publish now, else not
            if (Request["publish"] != null && Request["save"] == null)
            {
                activeValue = 1;
            }

            // if the user let one option blank is shown a message
            if (Request["publish"] == null && Request["save"] == null)
            {
                ViewBag.Msj = "Se debe seleccionar si desea Activar o Almacenar.";
            }

            // if the user wants the promotion to be save and ketp for later
            if (Request["publicar"] == null && Request["almacenar"] != null)
            {
                activeValue = 0;
            }

            // send the information to the database
            DBConnection.InsertNewPromotion(AdminModel.Id, valueTCS, finishDate, activeValue, 0);
            DBConnection.GetNewestIdPromotion(AdminModel.PromotionModel);
            int IdPromotion = AdminModel.PromotionModel.LatestIdPromotion;

            foreach (var item in dict)
            {
                DBConnection.InsertPromosMaterial(IdPromotion, item.Key, item.Value);
            }

            // if the promotion is active, make it a tweet
            if (activeValue == 1)
            {
                TwitterConnection.SetCredentials();
                TwitterConnection.Publish("Hay una nueva Promocion en Combo de: " + valueTCS + " TEColones. Consiste en entregar: ");
                foreach (var item in dict)
                {
                    TwitterConnection.Publish("Entregar " + item.Value + " kg " + " de " + item.Key);
                }
                TwitterConnection.Publish("La promocion es valida hasta: " + finishDate);
            }

            return(View("~/Views/Administrator/Promotion/CreateComboPromotion.cshtml", AdminModel));
        }