private ShopHistoryDTO ToDTO(ShopHistoryEntity shopHistoryEntity) { ShopHistoryDTO shopHistoryDTO = new ShopHistoryDTO() { CardId = shopHistoryEntity.CardId, Id = shopHistoryEntity.Id, UserId = shopHistoryEntity.UserId, UserName = shopHistoryEntity.User.UserName }; return(shopHistoryDTO); }
public long InsertShopHistory(ShopHistoryDTO t_ShopHistory) { using (B2CDbContext ctx = new B2CDbContext()) { ShopHistoryEntity shopHistoryEntity = new ShopHistoryEntity() { CardId = t_ShopHistory.CardId, UserId = t_ShopHistory.UserId }; ctx.ShopHistories.Add(shopHistoryEntity); ctx.SaveChanges(); return(shopHistoryEntity.Id); } }
public long UpdateShopHistory(ShopHistoryDTO t_ShopHistory) { using (B2CDbContext ctx = new B2CDbContext()) { BaseService <ShopHistoryEntity> bs = new BaseService <ShopHistoryEntity>(ctx); if (bs.GetAll().Any(e => e.Id == t_ShopHistory.Id)) { return(0); } else { var shopHistoryEntity = bs.GetById(t_ShopHistory.Id); shopHistoryEntity.UserId = t_ShopHistory.UserId; shopHistoryEntity.CardId = t_ShopHistory.CardId; ctx.SaveChanges(); return(shopHistoryEntity.Id); } } }