Beispiel #1
0
        public ActionResult Create([Bind(Include = "PlanID,PlanName,PlanDescription,Price,IsActive,IsUsed,Costo")] Plan plan)
        {
            bool error = false;

            try
            {
                if (!(plan.PlanName != null))
                {
                    ViewBag.VoidPlanName = "Se requiere llenar el campo correspondiente al nombre del plan";
                }
                if (error)
                {
                    throw new VoidValueException();
                }

                if (ModelState.IsValid)
                {
                    db.Plans.Add(plan);
                    db.SaveChanges();
                    Utilidades utl = new Utilidades();

                    if (!utl.IsRentable(plan.PlanID, Convert.ToDecimal(plan.Price)))
                    {
                        return(RedirectToAction("Edit", "Plan_Service", new { area = "" }));
                    }

                    foreach (var a in db.Plan_Service)
                    {
                        if (plan.PlanID == a.PlanID)
                        {
                            utl.ActualizarCosto(plan.PlanID, a.ServiceID);
                        }
                    }



                    return(RedirectToAction("Create", "Plan_Service", new { area = "" }));
                }
            }
            catch (VoidValueException)
            {
                ViewBag.ErrorMessage = "Faltan campos por llenar";
            }

            return(View(plan));
        }