public SaveResult InsertOrUpdate(ref BazaarItemDTO bazaarItem) { try { using (OpenNosContext context = DataAccessHelper.CreateContext()) { long bazaarItemId = bazaarItem.BazaarItemId; BazaarItem entity = context.BazaarItem.FirstOrDefault(c => c.BazaarItemId.Equals(bazaarItemId)); if (entity == null) { bazaarItem = Insert(bazaarItem, context); return(SaveResult.Inserted); } bazaarItem = Update(entity, bazaarItem, context); return(SaveResult.Updated); } } catch (Exception e) { Logger.Error($"BazaarItemId: {bazaarItem.BazaarItemId} Message: {e.Message}", e); return(SaveResult.Error); } }
private static BazaarItemDTO Insert(BazaarItemDTO bazaarItem, OpenNosContext context) { BazaarItem entity = new BazaarItem(); Mapper.Mappers.BazaarItemMapper.ToBazaarItem(bazaarItem, entity); context.BazaarItem.Add(entity); context.SaveChanges(); if (Mapper.Mappers.BazaarItemMapper.ToBazaarItemDTO(entity, bazaarItem)) { return(bazaarItem); } return(null); }
private static BazaarItemDTO Update(BazaarItem entity, BazaarItemDTO bazaarItem, OpenNosContext context) { if (entity != null) { Mapper.Mappers.BazaarItemMapper.ToBazaarItem(bazaarItem, entity); context.SaveChanges(); } if (Mapper.Mappers.BazaarItemMapper.ToBazaarItemDTO(entity, bazaarItem)) { return(bazaarItem); } return(null); }
public static bool ToBazaarItemDTO(BazaarItem input, BazaarItemDTO output) { if (input == null) { return(false); } output.Amount = input.Amount; output.BazaarItemId = input.BazaarItemId; output.DateStart = input.DateStart; output.Duration = input.Duration; output.IsPackage = input.IsPackage; output.ItemInstanceId = input.ItemInstanceId; output.MedalUsed = input.MedalUsed; output.Price = input.Price; output.SellerId = input.SellerId; return(true); }
public DeleteResult Delete(long bazaarItemId) { try { using (OpenNosContext context = DataAccessHelper.CreateContext()) { BazaarItem bazaarItem = context.BazaarItem.FirstOrDefault(c => c.BazaarItemId.Equals(bazaarItemId)); if (bazaarItem != null) { context.BazaarItem.Remove(bazaarItem); context.SaveChanges(); } return(DeleteResult.Deleted); } } catch (Exception e) { Logger.Error(string.Format(Language.Instance.GetMessageFromKey("DELETE_ERROR"), bazaarItemId, e.Message), e); return(DeleteResult.Error); } }