public ActionResult GetNextDateReminder(CRM_RemiderModel model) { CRMNextDateReminderRepository repo = new CRMNextDateReminderRepository(_context); DateTime NextDate = repo.GetNextDateRemind(model); return(Json(NextDate.ToString("dd/MM/yyyy"), JsonRequestBehavior.AllowGet)); }
public DateTime GetNextDateRemind(CRM_RemiderModel model) { model.DaysPriorNotice = model.DaysPriorNotice ?? 0; //Xét Tần suất if (model.PeriodType == EnumPeriodType.MOTLAN) { model.StartDate = null; model.NextDateRemind = model.ExpiryDate.Value.AddDays(model.DaysPriorNotice.Value * (-1)); } else //if (model.PeriodType == EnumPeriodType.DINHKY) { model.ExpiryDate = null; //model.NextDateRemind = model.StartDate.Value.AddDays(model.DaysPriorNotice.Value * (-1)); DateTime?NextDateRemind = model.StartDate; DateTime?StartDate = model.StartDate; while (NextDateRemind == null || NextDateRemind.Value.Date.AddDays(model.DaysPriorNotice.Value * (-1)).CompareTo(DateTime.Now.Date) <= 0) { switch (model.PeriodCode) { case ConstantPeriod.NGAY: NextDateRemind = StartDate.Value.AddDays(1); StartDate = NextDateRemind; break; case ConstantPeriod.TUAN: NextDateRemind = StartDate.Value.AddDays(7); StartDate = NextDateRemind; break; case ConstantPeriod.THANG: NextDateRemind = StartDate.Value.AddMonths(1); StartDate = NextDateRemind; break; case ConstantPeriod.QUY: NextDateRemind = StartDate.Value.AddMonths(3); StartDate = NextDateRemind; break; case ConstantPeriod.NAM: NextDateRemind = StartDate.Value.AddYears(1); StartDate = NextDateRemind; break; case ConstantPeriod.NNgay: NextDateRemind = StartDate.Value.AddDays(model.NDays.Value); StartDate = NextDateRemind; break; default: NextDateRemind = DateTime.Now.AddDays(1); break; } } model.NextDateRemind = NextDateRemind.Value.Date.AddDays(model.DaysPriorNotice.Value * (-1)); } return(model.NextDateRemind.Value); }
public ActionResult Create() { CRM_RemiderModel model = new CRM_RemiderModel() { Actived = true }; CreateViewBag(); return(View()); }
public ActionResult _PreviewEmail(string NextDateRemindPreview, CRM_RemiderModel model, List <CRMRemiderEmailParameterMappingViewModel> detail) { var ContentEmail = _context.CRM_EmailTemplateModel .Where(p => p.EmailTemplateId == model.EmailTemplateId) .Select(p => p.EmailContent) .FirstOrDefault(); if (detail != null) { foreach (var item in detail) { switch (item.Value) { case ConstantRemiderAUTOType.ExpDATE: ContentEmail = ContentEmail.Replace(item.EmailParameterName, model.ExpiryDate.Value.ToString("dd/MM/yyyy")); break; case ConstantRemiderAUTOType.SerCONTENT: ContentEmail = ContentEmail.Replace(item.EmailParameterName, model.ServiceContent); break; case ConstantRemiderAUTOType.SerPRICE: ContentEmail = ContentEmail.Replace(item.EmailParameterName, model.Price.Value.ToString("n0")); break; default: ContentEmail = ContentEmail.Replace(item.EmailParameterName, item.Value); break; } } } var modelPreview = new CRMPreviewViewModel() { Tile = _context.CRM_EmailTemplateModel .Where(p => p.EmailTemplateId == model.EmailTemplateId) .Select(p => p.EmailTitle) .FirstOrDefault(), Content = ContentEmail, NextDateRemindPreview = NextDateRemindPreview }; return(PartialView(modelPreview)); }
public ActionResult _PreviewSMS(string NextDateRemindPreview, CRM_RemiderModel model, List <CRMRemiderSMSParameterMappingViewModel> SMSPara) { var ContentSMS = _context.CRM_SMSTemplateModel .Where(p => p.SMSTemplateId == model.SMSTemplateId) .Select(p => p.SMSContent) .FirstOrDefault(); if (SMSPara != null) { foreach (var item in SMSPara) { switch (item.Value) { case ConstantRemiderAUTOType.ExpDATE: ContentSMS = ContentSMS.Replace(item.SMSParameterName, model.ExpiryDate.Value.ToString("dd/MM/yyyy")); break; case ConstantRemiderAUTOType.SerCONTENT: ContentSMS = ContentSMS.Replace(item.SMSParameterName, model.ServiceContent); break; case ConstantRemiderAUTOType.SerPRICE: ContentSMS = ContentSMS.Replace(item.SMSParameterName, model.Price.Value.ToString("n0")); break; default: ContentSMS = ContentSMS.Replace(item.SMSParameterName, item.Value); break; } } } var modelPreview = new CRMPreviewViewModel() { Content = ContentSMS, NextDateRemindPreview = NextDateRemindPreview }; return(PartialView(modelPreview)); }
public ActionResult Save(CRM_RemiderModel model, List <CRM_Remider_EmailParameter_Mapping> detail, List <CRM_Remider_SMSParameter_Mapping> SMSPara) { try { if (ModelState.IsValid) { using (TransactionScope ts = new TransactionScope()) { CRMNextDateReminderRepository repo = new CRMNextDateReminderRepository(_context); model.NextDateRemind = repo.GetNextDateRemind(model); _context.Entry(model).State = System.Data.Entity.EntityState.Added; _context.SaveChanges(); if (detail != null) { CRM_Remider_EmailParameter_Mapping RemiderEmailPara; foreach (var item in detail) { RemiderEmailPara = new CRM_Remider_EmailParameter_Mapping() { RemiderId = model.RemiderId, EmailTemplateId = model.EmailTemplateId.Value, EmailParameterId = item.EmailParameterId, ValueType = item.ValueType, Value = item.Value }; _context.Entry(RemiderEmailPara).State = System.Data.Entity.EntityState.Added; _context.SaveChanges(); } } if (SMSPara != null) { CRM_Remider_SMSParameter_Mapping RemiderSMSPara; foreach (var item in SMSPara) { RemiderSMSPara = new CRM_Remider_SMSParameter_Mapping() { RemiderId = model.RemiderId, SMSTemplateId = model.SMSTemplateId.Value, SMSParameterId = item.SMSParameterId, ValueType = item.ValueType, Value = item.Value }; _context.Entry(RemiderSMSPara).State = System.Data.Entity.EntityState.Added; _context.SaveChanges(); } } ts.Complete(); return(Json("success", JsonRequestBehavior.AllowGet)); } } else { return(Json("Vui lòng kiểm tra lại thông tin không hợp lệ", JsonRequestBehavior.AllowGet)); } } catch { return(Json(Resources.LanguageResource.AddErrorMessage, JsonRequestBehavior.AllowGet)); } }
public ActionResult Update(CRM_RemiderModel model, List <CRM_Remider_EmailParameter_Mapping> detail, List <CRM_Remider_SMSParameter_Mapping> SMSPara) { try { using (TransactionScope ts = new TransactionScope()) { CRMNextDateReminderRepository repo = new CRMNextDateReminderRepository(_context); model.NextDateRemind = repo.GetNextDateRemind(model); _context.Entry(model).State = System.Data.Entity.EntityState.Modified; _context.SaveChanges(); #region B1 : Xoá các Para cũ var Remidermodel = _context.CRM_RemiderModel .Include(p => p.CRM_Remider_EmailParameter_Mapping) .Include(p => p.CRM_Remider_SMSParameter_Mapping) .Where(p => p.RemiderId == model.RemiderId) .FirstOrDefault(); //Xoá EmailPara cũ if (Remidermodel.CRM_Remider_EmailParameter_Mapping.Count > 0) { while (Remidermodel.CRM_Remider_EmailParameter_Mapping.Count > 0) { _context.Entry(Remidermodel.CRM_Remider_EmailParameter_Mapping.First()).State = System.Data.Entity.EntityState.Deleted; _context.SaveChanges(); } } //Xoá SMSPara cũ if (Remidermodel.CRM_Remider_SMSParameter_Mapping.Count > 0) { while (Remidermodel.CRM_Remider_SMSParameter_Mapping.Count > 0) { _context.Entry(Remidermodel.CRM_Remider_SMSParameter_Mapping.First()).State = System.Data.Entity.EntityState.Deleted; _context.SaveChanges(); } } //Mapper.CreateMap<CRM_RemiderModel, CRM_RemiderModel>(); //Remidermodel = Mapper.Map<CRM_RemiderModel>(model); #endregion #region Insert Para mới if (detail != null) { CRM_Remider_EmailParameter_Mapping RemiderEmailPara; foreach (var item in detail) { RemiderEmailPara = new CRM_Remider_EmailParameter_Mapping() { RemiderId = model.RemiderId, EmailTemplateId = model.EmailTemplateId.Value, EmailParameterId = item.EmailParameterId, ValueType = item.ValueType, Value = item.Value }; _context.Entry(RemiderEmailPara).State = System.Data.Entity.EntityState.Added; _context.SaveChanges(); } } if (SMSPara != null) { CRM_Remider_SMSParameter_Mapping RemiderSMSPara; foreach (var item in SMSPara) { RemiderSMSPara = new CRM_Remider_SMSParameter_Mapping() { RemiderId = model.RemiderId, SMSTemplateId = model.SMSTemplateId.Value, SMSParameterId = item.SMSParameterId, ValueType = item.ValueType, Value = item.Value }; _context.Entry(RemiderSMSPara).State = System.Data.Entity.EntityState.Added; _context.SaveChanges(); } } #endregion ts.Complete(); return(Json("success", JsonRequestBehavior.AllowGet)); } } catch { return(Json(Resources.LanguageResource.EditErrorMessage, JsonRequestBehavior.AllowGet)); } }