public ActionResult AddPush(int? id)
        {
            if (AccessSalon(id).IsFalse())
            {
                return RedirectError();
            }

            var prestations = Bdd.GetTypePrestationsSalon(id);
            var model = new ViewModelAddPush(prestations);
            model.Authorize = Bdd.AuthorizeAddPush(id);
            return View(model);
        }
        public ActionResult AddPush(ViewModelAddPush model, int? id)
        {
            if (AccessSalon(id).IsFalse())
            {
                return RedirectError();
            }


            if (ModelState.IsValid)
            {
                var form = new RForm();
                var prestation = form.Get("prestations");

                if (prestation.IsNullOrEmpty())
                {
                    ViewBag.Error =
                        "Erreur lors de la récupération des prestations, vous devez en selectionner au moins une";
                }
                else
                {
                    var tabPrestations = prestation.Contains(",")
                    ? prestation.Split(',').ToList()
                    : new List<string>
                    {
                        prestation
                    };

                    if (tabPrestations.IsEmpty())
                    {
                        ViewBag.Error =
                            "Erreur lors de la récupération des prestations, vous devez en selectionner au moins une";
                    }
                    else
                    {
                        var date = form.Get("Date");
                        if (date.IsNullOrEmpty())
                        {
                            ViewBag.Error =
                            "Erreur lors de la récupération de la date, vous devez en selectionner une";
                        }
                        else
                        {
                            model.Form.Date = date.StringToDateTime();
                            if (Bdd.AddPush(id, tabPrestations, model))
                            {
                                TempData["Success"] = "Push bien ajouté";
                                return RedirectToRoute("Backend_salon_gererpush", new { id = id });
                            }

                            ViewBag.Error = "Erreur lors de l'ajout du push";
                        }
                    }
                }
            }

            var prestations = Bdd.GetTypePrestationsSalon(id);
            model.TypePrestations = prestations;
            model.SetTypePrestation(prestations);
            model.Authorize = Bdd.AuthorizeAddPush(id);
            return View(model);
        }
示例#3
0
        public bool AddPush(int? idSalon, List<string> prestationsId = null, ViewModelAddPush model = null)
        {
            try
            {
                if (model.IsNull() || prestationsId.IsEmpty() || idSalon.IsNull()) return false;
                if (model.Form.HeureDebut.IsNullOrEmpty() || model.Form.HeureDebut.Contains(':').IsFalse() ||
                    model.Form.HeureFin.IsNullOrEmpty() || model.Form.HeureFin.Contains(':').IsFalse()) return false;

                var salon = GetSalonById(idSalon);
                if (salon.IsNull()) return false;

                //On récup les type presta
                var listeTypePresta = prestationsId.Where(id => !id.IsNullOrEmpty())
                    .Select(id => TypePrestations.Find(id.ToInt()))
                    .Where(typePrestation => !typePrestation.IsNull()).ToList();

                if (listeTypePresta.IsEmpty()) return false;

                //Création du creneau
                var creneau = new Creneau(model.Form.HeureDebut, model.Form.HeureFin);

                var push = new Push
                {
                    TypePrestations = listeTypePresta,
                    NombreEmployes = model.Form.NombreEmployes,
                    Pourcentage = model.Form.Pourcentage,
                    Date = model.Form.Date,
                    Creneau = creneau,
                    IdSalon = (int)idSalon,
                };

                Pushes.Add(push);
                SaveChanges();
                return true;
            }
            catch (Exception)
            {
                return false;
            }
        }