Beispiel #1
0
        public IActionResult Nominee([FromServices] ICurrentUsers currentUsers, enmSaveStatus?_enmSaveStatus, enmMessage?_enmMessage)
        {
            mdlNominee mdl = new mdlNominee();

            if (_enmSaveStatus != null)
            {
                ViewBag.SaveStatus = (int)_enmSaveStatus.Value;
                ViewBag.Message    = _enmMessage?.GetDescription();
            }

            var masterData = _context.TblTcNominee.Where(p => p.TcNid == currentUsers.TcNid && !p.Isdeleted).FirstOrDefault();

            if (masterData != null)
            {
                mdl.NomineeName     = masterData.NomineeName;
                mdl.NomineeRelation = masterData.NomineeRelation;
                mdl.Remarks         = masterData.Remarks;
            }

            return(View(mdl));
        }
Beispiel #2
0
        public async Task <IActionResult> NomineeAsync([FromServices] ICurrentUsers currentUsers, mdlNominee mdl)
        {
            if (ModelState.IsValid)
            {
                var ExistingData = _context.TblTcNominee.FirstOrDefault(p => !p.Isdeleted && p.TcNid == currentUsers.TcNid);
                if (ExistingData != null) // for update the data
                {
                    //ExistingData.Isdeleted = true;
                    ExistingData.NomineeName      = mdl.NomineeName;
                    ExistingData.NomineeRelation  = mdl.NomineeRelation;
                    ExistingData.Remarks          = mdl.Remarks;
                    ExistingData.lastModifiedBy   = currentUsers.TcNid;
                    ExistingData.LastModifieddate = DateTime.Now;
                    _context.TblTcNominee.Update(ExistingData);
                    _context.SaveChanges();
                    return(RedirectToAction("Nominee",
                                            new { _enmSaveStatus = enmSaveStatus.success, _enmMessage = enmMessage.UpdateSucessfully }));
                }

                //if (_context.TblTcNominee.Any(p => p.TcNid == currentUsers.TcNid && !p.Isdeleted))
                //{
                //    ModelState.AddModelError("", "request already submited");
                //    ViewBag.savestatus = enmSaveStatus.warning;
                //    ViewBag.message = enmMessage.AlreadyExists.GetDescription();
                //}
                else
                {
                    _context.TblTcNominee.Add(new tblTcNominee
                    {
                        NomineeName     = mdl.NomineeName,
                        NomineeRelation = mdl.NomineeRelation,
                        CreatedBy       = currentUsers.TcNid,
                        CreatedDt       = DateTime.Now,
                        Remarks         = mdl.Remarks,
                        Isdeleted       = false,
                        TcNid           = currentUsers.TcNid,
                    });
                    _context.SaveChanges();
                    return(RedirectToAction("Nominee",
                                            new { _enmSaveStatus = enmSaveStatus.success, _enmMessage = enmMessage.SaveSucessfully }));
                }
            }

            return(View(mdl));
        }