コード例 #1
0
ファイル: ConverterHelper.cs プロジェクト: raudomoquete/SiPA
        public async Task <Wedding> ToWeddingAsync(WeddingVM model, bool isNew)
        {
            var wedding = new Wedding
            {
                WeedingDate          = model.WeedingDate,
                Id                   = isNew ? 0 : model.Id,
                PlaceOfEvent         = model.PlaceOfEvent,
                BrideFatherName      = model.BrideFatherName,
                BrideFatherId        = model.BrideFatherId,
                BrideMotherName      = model.BrideMotherName,
                BrideMotherId        = model.BrideMotherId,
                BrideGroomFatherName = model.BrideGroomFatherName,
                BrideGroomFatherId   = model.BrideGroomFatherId,
                BrideGroomMotherName = model.BrideGroomMotherName,
                BrideGroomMotherId   = model.BrideGroomMotherId,
                GodMother            = model.GodMother,
                GodMotherId          = model.GodMotherId,
                GodFather            = model.GodFather,
                GoFatherId           = model.GoFatherId,
                Comments             = model.Comments,
                CeremonialCelebrant  = model.CeremonialCelebrant,
                Parishioners         = await _dataContext.Parishioners.FindAsync(model.ParishionerId),
                SacramentType        = await _dataContext.SacramentTypes.FindAsync(model.SacramentTypeId)
            };

            return(wedding);
        }
コード例 #2
0
        public IActionResult CreateWedding(WeddingVM model)
        {
            int?UserId = HttpContext.Session.GetInt32("UserId");

            if (UserId == null)
            {
                return(RedirectToAction("Index", "Users"));
            }

            else
            {
                if (ModelState.IsValid)
                {
                    Wedding NewCreation = new Wedding();
                    NewCreation.UserId    = (int)UserId;
                    NewCreation.WedderOne = model.Wedder1;
                    NewCreation.WedderTwo = model.Wedder2;
                    NewCreation.Date      = model.Date;
                    NewCreation.Address   = model.Address;
                    _context.Weddings.Add(NewCreation);
                    _context.SaveChanges();
                    int WeddingId = _context.Weddings.Last().WeddingId;
                    // HttpContext.Session.SetInt32("WeddingId",WeddingId);
                    return(Redirect($"SingleWedding/{WeddingId}"));
                }
            }
            return(View("PlanWedding", model));
        }
コード例 #3
0
        public async Task <IActionResult> AddWedding(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            var parishioner = await _context.Parishioners.FindAsync(id.Value);

            if (parishioner == null)
            {
                return(NotFound());
            }

            var feligres = await _context.Parishioners
                           .Include(p => p.Weddings)
                           .FirstOrDefaultAsync(p => p.Id == id);

            if (feligres.Weddings.Count > 0)
            {
                ModelState.AddModelError("", "Solo puede agregar un Matrimonio por Feligrés");
            }

            var model = new WeddingVM
            {
                CreatedAt      = DateTime.Today,
                ParishionerId  = parishioner.Id,
                SacramentTypes = _combosHelper.GetWedding()
            };

            return(View(model));
        }
コード例 #4
0
        public async Task <IActionResult> EditWedding(WeddingVM model)
        {
            if (ModelState.IsValid)
            {
                var wedding = await _converterHelper.ToWeddingAsync(model, false);

                _context.Weddings.Update(wedding);
                await _context.SaveChangesAsync();

                return(RedirectToAction($"Details/{model.ParishionerId}"));
            }

            model.SacramentTypes = _combosHelper.GetWedding();
            return(View(model));
        }