public List <NoticeModel> GetNoticeListData(DateTime FromDate, DateTime ToDate) { ShomaRMEntities db = new ShomaRMEntities(); List <NoticeModel> lstpr = new List <NoticeModel>(); try { DataTable dtTable = new DataTable(); dtTable.Clear(); using (var cmd = db.Database.Connection.CreateCommand()) { db.Database.Connection.Open(); cmd.CommandText = "usp_GetNoticeList"; cmd.CommandType = CommandType.StoredProcedure; DbParameter paramF = cmd.CreateParameter(); paramF.ParameterName = "FromDate"; paramF.Value = FromDate; cmd.Parameters.Add(paramF); DbParameter paramC = cmd.CreateParameter(); paramC.ParameterName = "ToDate"; paramC.Value = ToDate; cmd.Parameters.Add(paramC); DbDataAdapter da = DbProviderFactories.GetFactory("System.Data.SqlClient").CreateDataAdapter(); da.SelectCommand = cmd; da.Fill(dtTable); db.Database.Connection.Close(); } foreach (DataRow dr in dtTable.Rows) { NoticeModel pr = new NoticeModel(); DateTime? noticeDate = null; try { noticeDate = Convert.ToDateTime(dr["NoticeDate"].ToString()); } catch { } pr.NoticeID = Convert.ToInt64(dr["NoticeID"].ToString()); pr.TenantName = dr["TenantName"].ToString(); pr.PidString = dr["PidString"].ToString(); pr.UidString = dr["UidString"].ToString(); pr.Revision_Num = Convert.ToInt32(dr["Revision_Num"].ToString()); pr.NoticeDateString = noticeDate == null ? "" : noticeDate.Value.ToString("MM/dd/yyy"); lstpr.Add(pr); } db.Dispose(); return(lstpr.ToList()); } catch (Exception ex) { db.Database.Connection.Close(); throw ex; } }
public string SaveUpdateNotice(NoticeModel model) { ShomaRMEntities db = new ShomaRMEntities(); string msg = ""; var leaseID = db.tbl_Lease.Where(p => p.TenantID == model.TID && p.Status == 1).FirstOrDefault(); if (model.NoticeID == 0) { var saveNotice = new tbl_Notice() { PID = model.PID, UID = model.UID, TID = model.TID, LeaseID = leaseID.LID, Revision_Num = model.Revision_Num, NoticeDate = model.NoticeDate, IntendedMoveOut = model.IntendedMoveOut, CancelNoticeDate = model.CancelNoticeDate, TerminationReason = model.TerminationReason, }; db.tbl_Notice.Add(saveNotice); db.SaveChanges(); msg = "Notice Saved Successfully"; } else { var getNOdata = db.tbl_Notice.Where(p => p.NoticeID == model.NoticeID).FirstOrDefault(); if (getNOdata != null) { getNOdata.PID = model.PID; getNOdata.UID = model.UID; getNOdata.TID = model.TID; getNOdata.LeaseID = leaseID.LID; getNOdata.Revision_Num = model.Revision_Num; getNOdata.NoticeDate = model.NoticeDate; getNOdata.IntendedMoveOut = model.IntendedMoveOut; getNOdata.CancelNoticeDate = model.CancelNoticeDate; getNOdata.TerminationReason = model.TerminationReason; } db.SaveChanges(); msg = "Notice Updated Successfully"; } db.Dispose(); return(msg); }
public NoticeModel GetNoticeDeatails(int id) { ShomaRMEntities db = new ShomaRMEntities(); NoticeModel model = new NoticeModel(); var getNoticeDet = db.tbl_Notice.Where(p => p.NoticeID == id).FirstOrDefault(); if (getNoticeDet != null) { model.PID = getNoticeDet.PID; model.UID = getNoticeDet.UID; model.TID = getNoticeDet.TID; model.LeaseID = getNoticeDet.LeaseID; model.Revision_Num = getNoticeDet.Revision_Num; model.NoticeDate = getNoticeDet.NoticeDate; model.IntendedMoveOut = getNoticeDet.IntendedMoveOut; model.CancelNoticeDate = getNoticeDet.CancelNoticeDate; model.TerminationReason = getNoticeDet.TerminationReason; model.NoticeID = id; } return(model); }