public override bool DeleteData(int id, out Library.DTO.Notification notification) { notification = new Library.DTO.Notification() { Type = Library.DTO.NotificationType.Success }; try { using (DocumentMonitoringMngEntities context = CreateContext()) { DocumentMonitoring dbItem = context.DocumentMonitoring.FirstOrDefault(o => o.DocumentMonitoringID == id); if (dbItem == null) { notification.Message = "document not found!"; return(false); } else { context.DocumentMonitoring.Remove(dbItem); context.SaveChanges(); return(true); } } } catch (Exception ex) { notification.Type = Library.DTO.NotificationType.Error; notification.Message = ex.Message; if (ex.InnerException != null && !string.IsNullOrEmpty(ex.InnerException.Message)) { notification.DetailMessage.Add(ex.InnerException.Message); } return(false); } }
public override bool UpdateData(int id, ref DTO.DocumentMonitoringMng.DocumentMonitoring dtoItem, out Library.DTO.Notification notification) { notification = new Library.DTO.Notification() { Type = Library.DTO.NotificationType.Success }; try { using (DocumentMonitoringMngEntities context = CreateContext()) { DocumentMonitoring dbItem = null; if (id == 0) { dbItem = new DocumentMonitoring(); context.DocumentMonitoring.Add(dbItem); } else { dbItem = context.DocumentMonitoring.FirstOrDefault(o => o.DocumentMonitoringID == id); } if (dbItem == null) { notification.Message = "invoice not found!"; return(false); } else { // check concurrency if (dbItem.ConcurrencyFlag != null && !dbItem.ConcurrencyFlag.SequenceEqual(Convert.FromBase64String(dtoItem.ConcurrencyFlag_String))) { throw new Exception(DALBase.Helper.TEXT_CONCURRENCY_CONFLICT); } //convert dto to db converter.DTO2DB_DocumentMonitoring(dtoItem, ref dbItem); context.SaveChanges(); //Get return data dtoItem = GetData(dbItem.DocumentMonitoringID, out notification); return(true); } } } catch (Exception ex) { notification.Type = Library.DTO.NotificationType.Error; notification.Message = ex.Message; if (ex.InnerException != null && !string.IsNullOrEmpty(ex.InnerException.Message)) { notification.DetailMessage.Add(ex.InnerException.Message); } return(false); } }
public bool QuickUpdateData(int UserID, ref List <DTO.DocumentMonitoringMng.DocumentMonitoringSearchUpdate> dtoItem, out Library.DTO.Notification notification) { notification = new Library.DTO.Notification() { Type = Library.DTO.NotificationType.Success }; try { using (DocumentMonitoringMngEntities context = CreateContext()) { foreach (DTO.DocumentMonitoringMng.DocumentMonitoringSearchUpdate item in dtoItem) { DocumentMonitoring dbItem = null; dbItem = context.DocumentMonitoring.FirstOrDefault(o => o.DocumentMonitoringID == item.DocumentMonitoringID); if (dbItem == null) { notification.Message = "Data not found!"; return(false); } else { if (item.IsEdit == 1) { converter.DTO2DB_QuickDocumentMonitoring(item, ref dbItem); dbItem.UpdatedBy = UserID; dbItem.UpdatedDate = DateTime.Now; } context.SaveChanges(); } } return(true); } } catch (Exception ex) { notification.Type = Library.DTO.NotificationType.Error; notification.Message = ex.Message; if (ex.InnerException != null && !string.IsNullOrEmpty(ex.InnerException.Message)) { notification.DetailMessage.Add(ex.InnerException.Message); } return(false); } }