public override bool Reset(int id, ref DTO.PLCMng.PLC dtoItem, out Library.DTO.Notification notification) { notification = new Library.DTO.Notification() { Type = Library.DTO.NotificationType.Success }; try { using (PLCMngEntities context = CreateContext()) { PLC dbItem = context.PLC.FirstOrDefault(o => o.PLCID == id); dbItem.IsConfirmed = false; dbItem.ConfirmedDate = null; dbItem.ConfirmedBy = null; context.SaveChanges(); return(true); } } catch (Exception ex) { notification.Type = Library.DTO.NotificationType.Error; notification.Message = ex.Message; return(false); } }
public override bool UpdateData(int id, ref DTO.PLCMng.PLC dtoItem, out Library.DTO.Notification notification) { notification = new Library.DTO.Notification() { Type = Library.DTO.NotificationType.Success }; try { using (PLCMngEntities context = CreateContext()) { PLC dbItem = null; if (id == 0) { dbItem = new PLC(); context.PLC.Add(dbItem); } else { dbItem = context.PLC.FirstOrDefault(o => o.PLCID == id); } if (dbItem == null) { notification.Message = "PLC 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); } converter.DTO2DB(dtoItem, this._TempFolder, ref dbItem); dbItem.UpdatedBy = dtoItem.UpdatedBy; dbItem.UpdatedDate = DateTime.Now; if (dtoItem.isRated) { dbItem.RatedBy = dtoItem.UpdatedBy; dbItem.RatedDate = DateTime.Now; } context.PLCImage.Local.Where(o => o.PLC == null).ToList().ForEach(o => context.PLCImage.Remove(o)); context.SaveChanges(); dtoItem = GetData(dbItem.PLCID, -1, -1, -1, -1, out notification).Data; return(true); } } } catch (Exception ex) { notification = new Library.DTO.Notification() { Message = ex.Message, Type = Library.DTO.NotificationType.Error }; return(false); } }
public override bool DeleteData(int id, out Library.DTO.Notification notification) { notification = new Library.DTO.Notification() { Type = Library.DTO.NotificationType.Success }; try { using (PLCMngEntities context = CreateContext()) { PLC dbItem = context.PLC.FirstOrDefault(o => o.PLCID == id); if (dbItem == null) { notification.Message = "PLC not found!"; return(false); } else { Module.Framework.DAL.DataFactory frameworkFactory = new Module.Framework.DAL.DataFactory(); foreach (PLCImage dbImage in dbItem.PLCImage) { if (!string.IsNullOrEmpty(dbImage.ImageFile)) { // remove image frameworkFactory.RemoveImageFile(dbImage.ImageFile); } } context.PLC.Remove(dbItem); context.SaveChanges(); return(true); } } } catch (Exception ex) { notification = new Library.DTO.Notification() { Message = ex.Message }; return(false); } }