Exemplo n.º 1
0
        public ActionResult Create([Bind(Include = "Id,Tarih,NobetGrupGorevTipId,NobetGunKuralId,BayramTurId")] BayramCoklu bayramCoklu)
        {
            if (ModelState.IsValid)
            {
                var bayramlar = new List <Bayram>();

                foreach (var nobetGrupGorevTipId in bayramCoklu.NobetGrupGorevTipId)
                {
                    bayramlar.Add(new Bayram
                    {
                        TakvimId            = _takvimService.GetByTarih(bayramCoklu.Tarih).Id,
                        NobetGunKuralId     = bayramCoklu.NobetGunKuralId,
                        NobetGrupGorevTipId = nobetGrupGorevTipId,
                        BayramTurId         = bayramCoklu.BayramTurId
                    });
                }

                var eklenecekbayramSayisi = bayramlar.Count;

                if (ModelState.IsValid && eklenecekbayramSayisi > 0)
                {
                    _bayramService.CokluEkle(bayramlar);
                    TempData["EklenenBayramSayisi"] = eklenecekbayramSayisi;
                    return(RedirectToAction("Index"));
                }
                return(RedirectToAction("Index"));
            }

            var user         = _userService.GetByUserName(User.Identity.Name);
            var nobetGruplar = _nobetGrupService.GetListByUser(user);

            var nobetGrupGorevTipler = _nobetGrupGorevTipService.GetDetaylar()
                                       .Where(w => nobetGruplar.Select(s => s.Id).Contains(w.NobetGrupId))
                                       .Select(s => new MyDrop {
                Id = s.Id, Value = $"{s.NobetGrupAdi}, {s.NobetGorevTipAdi}"
            });

            ViewBag.BayramTurId         = new SelectList(_bayramTurService.GetList(), "Id", "Adi", bayramCoklu.BayramTurId);
            ViewBag.NobetGrupGorevTipId = new SelectList(nobetGrupGorevTipler, "Id", "Value");
            ViewBag.NobetGunKuralId     = new SelectList(_nobetGunKuralService.GetList().Where(w => w.Id > 7), "Id", "Adi", bayramCoklu.NobetGunKuralId);
            ViewBag.TakvimId            = new SelectList(_takvimService.GetList(), "Id", "Tarih", bayramCoklu.Tarih);
            return(View(bayramCoklu));
        }