public JsonResult AddNewQuazi(Quazi quazi) { var quaziInvestigation = context.Quazies.Where(x => x.NidNo == quazi.NidNo) .Select(x => x) .FirstOrDefault(); if (quaziInvestigation != null) { return(new JsonResult { Data = quaziInvestigation, JsonRequestBehavior = JsonRequestBehavior.AllowGet }); } else if (quazi != null) { var now = DateTime.Now; var year = Convert.ToString(now.Year); var month = now.Month.ToString("00"); var date = now.Day.ToString("00"); var fomat = year + month + date; var maxId = 0; if (context.Quazies.Any(m => m.RegistrationNo.StartsWith(fomat)) && context.Quazies.Count() != 0) { maxId = context.Quazies .Where(m => m.RegistrationNo.StartsWith(fomat)) .Select(m => m.RegistrationNo.Substring(fomat.Length)).AsEnumerable() .Select(int.Parse) .Max() + 1; } var RegistrationNo = fomat + (maxId.ToString().PadLeft(5, '0')); quazi.RegistrationNo = RegistrationNo; context.Quazies.Add(quazi); context.SaveChanges(); Generator.IsReport = "IsOk"; Generator.Message = "Add new quazi"; } return(new JsonResult { Data = new { Generator.IsReport, Generator.Message }, JsonRequestBehavior = JsonRequestBehavior.AllowGet }); }
public JsonResult CreateNid(NID nid) { try { var postCode = Convert.ToString(nid.PostCode); var now = nid.DoB; var year = Convert.ToString(now.Year); var month = now.Month.ToString("00"); var date = now.Day.ToString("00"); var fomat = postCode + year + month + date; var maxId = 0; if (_context.Nids.Any(m => m.NidNo.StartsWith(fomat)) && _context.Nids.Count() != 0) { maxId = _context.Nids .Where(m => m.NidNo.StartsWith(fomat)) .Select(m => m.NidNo.Substring(fomat.Length)).AsEnumerable() .Select(int.Parse) .Max() + 1; } var NidNo = fomat + (maxId.ToString().PadLeft(7, '0')); nid.NidNo = NidNo; var today = DateTime.Today; var a = (today.Year * 100 + today.Month) * 100 + today.Day; var b = (nid.DoB.Year * 100 + nid.DoB.Month) * 100 + nid.DoB.Day; var age = (a - b) / 10000; if (age >= 18) { _context.Nids.Add(nid); _context.SaveChanges(); Generator.IsReport = "Ok"; Generator.Message = "Mr." + nid.Name + " NID number is " + NidNo; } else { Generator.IsReport = "NotOk"; Generator.Message = "Data Not Add on NID"; } } catch (Exception ex) { Generator.IsReport = "NotOk"; Generator.Message = ex.Message; } return(new JsonResult { Data = new { Generator.IsReport, Generator.Message }, JsonRequestBehavior = JsonRequestBehavior.AllowGet }); }
public JsonResult RegistrarMarriage(MarriageDto marriageDto) { try { var now = DateTime.Now; var year = now.Year; var month = now.Month.ToString("00"); var date = now.Day.ToString("00"); var fomat = year + month + date; var maxId = 0; if (context.Marriages.Any(m => m.MarriageRegistrationNo.StartsWith(fomat))) { maxId = context.Marriages .Where(m => m.MarriageRegistrationNo.StartsWith(fomat)) .Select(m => m.MarriageRegistrationNo.Substring(fomat.Length)).AsEnumerable() .Select(int.Parse) .Max() + 1; } var MarriageRegistrationNo = fomat + (maxId.ToString().PadLeft(5, '0')); var BrideMarriageCount = context.Couples.Where(x => x.BrNidNo == marriageDto.BrNidNo).Count(); var BridegroomMarriageCount = context.Couples.Where(x => x.BgNidNo == marriageDto.BgNidNo).Count(); var couple = new Couple(); couple.BrName = marriageDto.BrName; couple.BrFName = marriageDto.BrFName; couple.BrMName = marriageDto.BrMName; couple.BrDoB = marriageDto.BrDoB; couple.BrAddress = marriageDto.BrAddress; couple.BrMobileNo = marriageDto.BrMobileNo; couple.BrNidNo = marriageDto.BrNidNo; couple.BgName = marriageDto.BgName; couple.BgFName = marriageDto.BgFName; couple.BgMName = marriageDto.BgMName; couple.BgDoB = marriageDto.BgDoB; couple.BgAddress = marriageDto.BgAddress; couple.BgNidNo = marriageDto.BgNidNo; couple.BgMarriageCount = BridegroomMarriageCount++; couple.BrMarriageCount = BrideMarriageCount++; context.Couples.Add(couple); context.SaveChanges(); var CoupleId = couple.Id; var moulovi = new Moulovi(); moulovi.MouloviName = marriageDto.MouloviName; moulovi.MobileNo = marriageDto.MouloviMobileNo; moulovi.Address = marriageDto.MouloviAddress; moulovi.NidNo = marriageDto.MouloviNidNo; context.Moulovies.Add(moulovi); context.SaveChanges(); var MouloviId = moulovi.Id; var attorney = new Attorney(); attorney.BrAttorneyName = marriageDto.BrAttorneyName; attorney.BrAttorneyAddress = marriageDto.BrAttorneyAddress; attorney.BgAttorneyName = marriageDto.BgAttorneyName; attorney.BgAttorneyAddress = marriageDto.BgAttorneyAddress; context.Attornies.Add(attorney); context.SaveChanges(); var AttorneyId = attorney.Id; var marriage = new Marriage(); marriage.CoupleId = CoupleId; marriage.MouloviId = MouloviId; marriage.AtorneyId = AttorneyId; marriage.MarriageRegistrationNo = MarriageRegistrationNo; marriage.MarriageDate = DateTime.Now; marriage.MarriageRegistrationFee = marriageDto.MarriageRegistrationFee; context.Marriages.Add(marriage); context.SaveChanges(); Generator.IsReport = "IsOk"; Generator.Message = "Congratulate the newlyweds Mr." + marriageDto.BgName + " && Mrs." + marriageDto.BrName + ". Yours Marriage Registrar Number: " + MarriageRegistrationNo; } catch (Exception ex) { Generator.IsReport = "NotOk"; Generator.Message = ex.Message; } return(new JsonResult { Data = new { Generator.IsReport, Generator.Message }, JsonRequestBehavior = JsonRequestBehavior.AllowGet }); }