public static DTO_CUS_Version toDTO(tbl_CUS_Version dbResult) { if (dbResult != null) { return(new DTO_CUS_Version() { IDPartner = dbResult.IDPartner, ID = dbResult.ID, Code = dbResult.Code, Name = dbResult.Name, Remark = dbResult.Remark, Sort = dbResult.Sort, IsDisabled = dbResult.IsDisabled, IsDeleted = dbResult.IsDeleted, CreatedBy = dbResult.CreatedBy, ModifiedBy = dbResult.ModifiedBy, CreatedDate = dbResult.CreatedDate, ModifiedDate = dbResult.ModifiedDate, VersionDate = dbResult.VersionDate, }); } else { return(null); } }
public static void update_CUS_Version(AppEntities db, int?PartnerID, string Code, DateTime VersionDate, string Username) { tbl_CUS_Version dbitem = db.tbl_CUS_Version.FirstOrDefault(d => d.IDPartner == PartnerID && d.Code == Code); bool isNewItem = dbitem == null; if (isNewItem) { dbitem = new tbl_CUS_Version(); dbitem.IDPartner = PartnerID; dbitem.Code = Code; dbitem.CreatedBy = Username; dbitem.CreatedDate = DateTime.Now; db.tbl_CUS_Version.Add(dbitem); } dbitem.VersionDate = VersionDate; dbitem.ModifiedBy = Username; dbitem.ModifiedDate = DateTime.Now; try { db.SaveChanges(); } catch (DbEntityValidationException e) { errorLog.logMessage("update_CUS_Version", e); } }
public static DTO_CUS_Version post_CUS_Version(AppEntities db, int PartnerID, DTO_CUS_Version item, string Username) { tbl_CUS_Version dbitem = new tbl_CUS_Version(); if (item != null) { dbitem.Code = item.Code; dbitem.Name = item.Name; dbitem.Remark = item.Remark; dbitem.Sort = item.Sort; dbitem.IsDisabled = item.IsDisabled; dbitem.IsDeleted = item.IsDeleted; dbitem.VersionDate = item.VersionDate; dbitem.CreatedBy = Username; dbitem.CreatedDate = DateTime.Now; dbitem.ModifiedBy = Username; dbitem.ModifiedDate = DateTime.Now; dbitem.IDPartner = PartnerID; try { db.tbl_CUS_Version.Add(dbitem); db.SaveChanges(); BS_CUS_Version.update_CUS_Version(db, dbitem.IDPartner, "DTO_CUS_Version", dbitem.ModifiedDate, Username); item.ID = dbitem.ID; item.CreatedBy = dbitem.CreatedBy; item.CreatedDate = dbitem.CreatedDate; item.ModifiedBy = dbitem.ModifiedBy; item.ModifiedDate = dbitem.ModifiedDate; item.IDPartner = dbitem.IDPartner; } catch (DbEntityValidationException e) { errorLog.logMessage("post_CUS_Version", e); item = null; } } return(item); }