public override object Get(int id) { var acc = _context.Notifications .Where(p => p.Id == id && (p.IsDeleted.HasValue == false || (p.IsDeleted.HasValue == true && p.IsDeleted.Value == false))) .FirstOrDefault <Notification>(); BO.Notification acc_ = Convert <BO.Notification, Notification>(acc); if (acc_ == null) { return(new BO.ErrorObject { ErrorMessage = "No record found.", errorObject = "", ErrorLevel = ErrorLevel.Error }); } return((object)acc_); }
public override T Convert <T, U>(U entity) { if (entity is Notification) { Notification notification = entity as Notification; if (notification == null) { return(default(T)); } BO.Notification notificationBO = new BO.Notification(); notificationBO.ID = notification.Id; notificationBO.CompanyId = notification.CompanyId; notificationBO.LocationId = notification.LocationId; notificationBO.StartDate = notification.StartDate; notificationBO.EndDate = notification.EndDate; notificationBO.IsViewed = notification.IsViewed; notificationBO.CreateByUserID = notification.CreateByUserID; if (notification.IsDeleted.HasValue) { notificationBO.IsDeleted = notification.IsDeleted.Value; } if (notification.UpdateByUserID.HasValue) { notificationBO.UpdateByUserID = notification.UpdateByUserID.Value; } //if (notification.Company != null) //{ // BO.Company boCompany = new BO.Company(); // using (CompanyRepository cmp = new CompanyRepository(_context)) // { // boCompany = cmp.Convert<BO.Company, Company>(notification.Company); // notificationBO.Company = boCompany; // } //} //if (notification.Location != null) //{ // BO.Location boLocation = new BO.Location(); // using (LocationRepository cmp = new LocationRepository(_context)) // { // boLocation = cmp.Convert<BO.Location, Location>(notification.Location); // notificationBO.Location = boLocation; // } //} return((T)(object)notificationBO); } else if (entity is CalendarEvent) { CalendarEvent CalendarEventDB = entity as CalendarEvent; if (CalendarEventDB == null) { return(default(T)); } BO.CalendarEvent CalendarEvent = new BO.CalendarEvent(); using (CalendarEventRepository calEventRep = new CalendarEventRepository(_context)) { CalendarEvent = calEventRep.Convert <BO.CalendarEvent, CalendarEvent>(CalendarEventDB); } return((T)(object)CalendarEvent); } return(default(T)); }
public override object Save <T>(T entity) { BO.Notification NotificationBO = (BO.Notification)(object) entity; Notification NotificationDB = new Notification(); using (var dbContextTransaction = _context.Database.BeginTransaction()) { bool IsEditMode = false; IsEditMode = (NotificationBO != null && NotificationBO.ID > 0) ? true : false; #region Notification if (NotificationBO != null && ((NotificationBO.ID <= 0 && NotificationBO.CompanyId.HasValue == true && NotificationBO.LocationId.HasValue == true) || (NotificationBO.ID > 0))) { bool Add_NotificationDB = false; NotificationDB = _context.Notifications.Where(p => p.Id == NotificationBO.ID).FirstOrDefault(); if (NotificationDB == null && NotificationBO.ID <= 0) { NotificationDB = new Notification(); Add_NotificationDB = true; } else if (NotificationDB == null && NotificationBO.ID > 0) { dbContextTransaction.Rollback(); return(new BO.ErrorObject { errorObject = "", ErrorMessage = "Notification Id dosent exists.", ErrorLevel = ErrorLevel.Error }); } NotificationDB.CompanyId = IsEditMode == true && NotificationBO.CompanyId.HasValue == false ? NotificationDB.CompanyId : NotificationBO.CompanyId.Value; NotificationDB.LocationId = IsEditMode == true && NotificationBO.LocationId.HasValue == false ? NotificationDB.LocationId : NotificationBO.LocationId.Value; NotificationDB.NotificationMessage = IsEditMode == true && NotificationBO.NotificationMessage == null ? NotificationDB.NotificationMessage : NotificationBO.NotificationMessage; NotificationDB.StartDate = IsEditMode == true && NotificationBO.StartDate == null ? NotificationDB.StartDate : NotificationBO.StartDate; NotificationDB.EndDate = IsEditMode == true && NotificationBO.EndDate == null ? NotificationDB.EndDate : NotificationBO.EndDate; NotificationDB.IsViewed = NotificationBO.IsViewed; NotificationDB.IsDeleted = NotificationBO.IsDeleted.HasValue ? NotificationBO.IsDeleted : false; if (IsEditMode == false) { NotificationDB.CreateByUserID = NotificationBO.CreateByUserID; NotificationDB.CreateDate = DateTime.UtcNow; } else { NotificationDB.UpdateByUserID = NotificationBO.UpdateByUserID; NotificationDB.UpdateDate = DateTime.UtcNow; } if (Add_NotificationDB == true) { NotificationDB = _context.Notifications.Add(NotificationDB); } _context.SaveChanges(); } else { if (IsEditMode == false) { dbContextTransaction.Rollback(); return(new BO.ErrorObject { errorObject = "", ErrorMessage = "Please pass valid Notification details.", ErrorLevel = ErrorLevel.Error }); } NotificationDB = null; } _context.SaveChanges(); #endregion dbContextTransaction.Commit(); if (NotificationDB != null) { NotificationDB = _context.Notifications .Where(p => p.Id == NotificationDB.Id && (p.IsDeleted.HasValue == false || (p.IsDeleted.HasValue == true && p.IsDeleted.Value == false))) .FirstOrDefault <Notification>(); } } var res = Convert <BO.Notification, Notification>(NotificationDB); return((object)res); }