public EquipmentInfo SaveEquipment4App(EquipmentInfo info, List <UploadFileInfo> files, UserInfo user) { if (info.EquipmentStatus.ID != EquipmentInfo.EquipmentStatuses.Scrap) { info.ScrapDate = DateTime.MinValue; } else if (info.ScrapDate == DateTime.MinValue) { info.ScrapDate = DateTime.Today; } if (string.IsNullOrEmpty(info.AssetCode)) { string date = DateTime.Today.Year + DateTime.Today.Month.ToString("D2") + DateTime.Today.Day.ToString("D2"); info.AssetCode = this.equipmentDao.GetNextAssetCode(date); } if (info.ID == 0) { info = this.equipmentDao.AddEquipment(info, user); DataTable dt = new DataTable(); dt.Columns.Add("FieldName"); dt.Columns.Add("OldValue"); dt.Columns.Add("NewValue"); dt.Rows.Add("EquipmentName", "", info.Name); dt.Rows.Add("AssetCode", "", info.AssetCode); this.auditManager.AddAuditLog(user.ID, ObjectTypes.Equipment, info.ID, dt, AuditHdrInfo.AuditOperations.Add); } else { EquipmentInfo existingInfo = this.equipmentDao.GetEquipmentByID(info.ID); info.Supplier.Name = info.Supplier.ID == 0 ? "" : this.supplierDao.GetSupplier(info.Supplier.ID).Name; info.Manufacturer.Name = info.Manufacturer.ID == 0 ? "" : this.supplierDao.GetSupplier(info.Manufacturer.ID).Name; info.EquipmentClass1.Code = SQLUtil.TrimNull(info.EquipmentClass1.Code == null ? "00" : info.EquipmentClass1.Code); info.EquipmentClass2.Code = SQLUtil.TrimNull(info.EquipmentClass2.Code == null ? "00" : info.EquipmentClass2.Code); info.EquipmentClass3.Code = SQLUtil.TrimNull(info.EquipmentClass3.Code == null ? "00" : info.EquipmentClass3.Code); info.FujiClass2.Name = this.fujiClassDao.GetFujiClass2ByID(info.FujiClass2.ID).Name; DataTable dtField = existingInfo.GetChangedFields(info); if (dtField.Rows.Count > 0) { this.equipmentDao.UpdateEquipment(info, user); this.auditManager.AddAuditLog(user.ID, ObjectTypes.Equipment, info.ID, dtField); } } if (files != null && files.Count > 0) { foreach (UploadFileInfo file in files) { file.ObjectID = info.ID; file.ObjectTypeId = ObjectTypes.Equipment; this.fileManager.SaveUploadFile(file); } } return(info); }
public EquipmentInfo SaveEquipment(EquipmentInfo info, List <UploadFileInfo> files, UserInfo user) { if (info.EquipmentStatus.ID != EquipmentInfo.EquipmentStatuses.Scrap) { info.ScrapDate = DateTime.MinValue; } else if (info.ScrapDate == DateTime.MinValue) { info.ScrapDate = DateTime.Today; } if (string.IsNullOrEmpty(info.AssetCode)) { string date = DateTime.Today.Year + DateTime.Today.Month.ToString("D2") + DateTime.Today.Day.ToString("D2"); info.AssetCode = this.equipmentDao.GetNextAssetCode(date); } if (info.ID == 0) { info = this.equipmentDao.AddEquipment(info, user); if (files != null && files.Count > 0) { foreach (UploadFileInfo file in files) { file.ObjectID = info.ID; file.ObjectName = ObjectTypes.Equipment; this.fileManager.SaveUploadFile(file); } } DataTable dt = new DataTable(); dt.Columns.Add("FieldName"); dt.Columns.Add("OldValue"); dt.Columns.Add("NewValue"); dt.Rows.Add("EquipmentName", "", info.Name); dt.Rows.Add("AssetCode", "", info.AssetCode); this.auditManager.AddAuditLog(user.ID, BusinessObjects.Domain.AuditHdrInfo.AuditObjectTypes.Equipment, info.ID, dt, AuditHdrInfo.AuditOperations.Add); } else { EquipmentInfo existingInfo = this.equipmentDao.GetEquipmentByID(info.ID); DataTable dtField = existingInfo.GetChangedFields(info); if (dtField.Rows.Count > 0) { this.equipmentDao.UpdateEquipment(info, user); this.auditManager.AddAuditLog(user.ID, BusinessObjects.Domain.AuditHdrInfo.AuditObjectTypes.Equipment, info.ID, dtField); } } return(info); }