public IHttpActionResult BGAutoReminderForVendor() { YSCMEntities db = new YSCMEntities(); VSCMEntities vscm = new VSCMEntities(); var bgList = db.BankGuarantees.Where(li => li.BGExpiryDate != null && (li.BGStatus == "Verified" || li.BGStatus == "Expired")).ToList(); foreach (var item in bgList) { //if bg expiry date- one month == current date && bg expiry date & warranty Expirydate difference should be greater than 6 months DateTime bgExpiryDate = Convert.ToDateTime(item.BGExpiryDate); DateTime WarrantyExpiryDate = Convert.ToDateTime(item.WarrantyExpiryDate); var autoDate = bgExpiryDate.AddMonths(-1).ToShortDateString(); var currentDate = DateTime.Now.ToShortDateString(); var months = (WarrantyExpiryDate.Month - bgExpiryDate.Month) + 12 * (WarrantyExpiryDate.Year - bgExpiryDate.Year); if (autoDate == currentDate && months > 1) { if (item.BGId != null) { var RemoteBankGuarantee = vscm.RemoteBankGuarantees.Where(li => li.BGId == item.BGId).FirstOrDefault(); RemoteBankGuarantee.IsBGRevised = false; vscm.SaveChanges(); } //local var LocalBG = db.BankGuarantees.Where(li => li.BGId == item.BGId).FirstOrDefault(); if (LocalBG != null) { LocalBG.IsBGRevised = false; db.SaveChanges(); } var Remarks = "Your BG is Expiring Soon, Please Re submit the revised BG for BG No: " + item.BGNo + "; PO No:" + item.PONo + " "; this.emailTemplateDA.sendBGInitiationmail(item.BGId, item.CreatedBy, Remarks, "ReSubmit"); } //BG Expired when vendor not submit documents int cmp = bgExpiryDate.AddDays(1).CompareTo(DateTime.Now); // if cmp value < 0 means bgexpiry date is less than current date, current date is greater means bgExpiryDate is comes after current date if (item.IsBGRevised == false && cmp < 0 && item.BGStatus != "Expired") { //update BG status track status track BGStatusTrack bgst = new BGStatusTrack(); bgst.BGId = item.BGId; bgst.Status = "Expired"; bgst.UpdatedBy = item.CreatedBy; this._mprBusenessAcess.updateBGStatus(bgst); } if (WarrantyExpiryDate.ToShortDateString() == currentDate && item.BGStatus != "Closed") { //update BG status track status track BGStatusTrack bgst = new BGStatusTrack(); bgst.BGId = item.BGId; bgst.Status = "Closed"; bgst.UpdatedBy = item.CreatedBy; this._mprBusenessAcess.updateBGStatus(bgst); } } return(Ok(true)); }
/*Name of Function : <<ASNInitiate>> Author :<<Prasanna>> * Date of Creation <<18-12-2020>> * Purpose : <<function is used to get ASN Initiate>> * Review Date :<<>> Reviewed By :<<>>*/ public bool ASNInitiate(ASNInitiation asnASNInitiation) { try { int vendorid = Convert.ToInt32(asnASNInitiation.VendorId); //check vuserid exist or not if not exist adding credentials in vendorusermaster tables List <string> EmailList = asnASNInitiation.VendorEmailId.Split(new char[] { ',' }).ToList(); foreach (var item in EmailList) { Int32 sequenceNo = 0; string password = ""; var value = ""; RemoteVendorUserMaster vendorUsermaster = vscm.RemoteVendorUserMasters.Where(li => li.Vuserid == item && li.VendorId == asnASNInitiation.VendorId).FirstOrDefault(); //need to implement vUniqueId value if (vendorUsermaster == null && !string.IsNullOrEmpty(item)) { RemoteVendorUserMaster vendorUsermasters = new RemoteVendorUserMaster(); sequenceNo = Convert.ToInt32(vscm.RemoteVendorUserMasters.Max(li => li.SequenceNo)); if (sequenceNo == null || sequenceNo == 0) { sequenceNo = 1; } else { sequenceNo = sequenceNo + 1; } value = obj.SP_sequenceNumber(sequenceNo).FirstOrDefault(); vendorUsermasters.VuniqueId = "C" + value; vendorUsermasters.SequenceNo = sequenceNo; vendorUsermasters.Vuserid = item.Replace(" ", String.Empty); password = this.mprDA.GeneratePassword(); vendorUsermasters.pwd = password; vendorUsermasters.ContactNumber = null; vendorUsermasters.ContactPerson = null; vendorUsermasters.VendorId = vendorid; vendorUsermasters.Active = true; vendorUsermasters.SuperUser = true; vendorUsermasters.UpdatedBy = asnASNInitiation.InitiateFrom; vendorUsermasters.UpdatedOn = DateTime.Now; vscm.RemoteVendorUserMasters.Add(vendorUsermasters); vscm.SaveChanges(); } VendorUserMaster Localvenmaster = obj.VendorUserMasters.Where(li => li.Vuserid == item && li.VendorId == vendorid).FirstOrDefault <VendorUserMaster>(); if (Localvenmaster == null && !string.IsNullOrEmpty(item)) { RemoteVendorUserMaster venmaster = vscm.RemoteVendorUserMasters.Where(li => li.Vuserid == item && li.VendorId == vendorid).FirstOrDefault <RemoteVendorUserMaster>(); VendorUserMaster vendorUsermasters = new VendorUserMaster(); vendorUsermasters.Vuserid = venmaster.Vuserid; vendorUsermasters.pwd = venmaster.pwd; vendorUsermasters.VendorId = venmaster.VendorId; vendorUsermasters.ContactNumber = venmaster.ContactNumber; vendorUsermasters.ContactPerson = venmaster.ContactPerson; vendorUsermasters.Active = true; vendorUsermasters.SuperUser = true; vendorUsermasters.VuniqueId = venmaster.VuniqueId; vendorUsermasters.SequenceNo = venmaster.SequenceNo; vendorUsermasters.UpdatedBy = venmaster.UpdatedBy; vendorUsermasters.UpdatedOn = DateTime.Now; obj.VendorUserMasters.Add(vendorUsermasters); obj.SaveChanges(); } } ASNInitiation asnIniLocal = new ASNInitiation(); asnIniLocal.VendorId = vendorid; asnIniLocal.VendorEmailId = asnASNInitiation.VendorEmailId; asnIniLocal.Remarks = asnASNInitiation.Remarks; asnIniLocal.InitiateFrom = asnASNInitiation.InitiateFrom; asnIniLocal.CreatedDate = DateTime.Now; obj.ASNInitiations.Add(asnIniLocal); obj.SaveChanges(); this.emailTemplateDA.sendASNInitiationEmail(asnIniLocal); } catch (DbEntityValidationException e) { foreach (var eve in e.EntityValidationErrors) { Console.WriteLine("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:", eve.Entry.Entity.GetType().Name, eve.Entry.State); foreach (var ve in eve.ValidationErrors) { log.ErrorMessage("ASNDA", "ASNInitiate", ve.ErrorMessage); Console.WriteLine("- Property: \"{0}\", Error: \"{1}\"", ve.PropertyName, ve.ErrorMessage); } } } return(true); }