public StoreDto GetStoreById(int id) { StoreDto dto = null; var context = new orderstatusEntities(); try { stores_data storeContext = context.stores_data.Where(x => x.id == id).SingleOrDefault(); if (storeContext != null) { dto = new StoreDto(); dto.Id = storeContext.id; dto.Url = storeContext.url; dto.Name = storeContext.name; dto.ApiKey = storeContext.api_key; dto.Interval = int.Parse(storeContext.interval.ToString()); dto.CustomShipmentsDtos = GetCustomShipmentByStoreId(storeContext.id); } return(dto); } catch (Exception ex) { log.Error("Error Exception GetStoreById: " + ex.Message); throw; } finally { context.Dispose(); } }
public int AddStore(StoreDto store) { var context = new orderstatusEntities(); try { stores_data storeContext = new stores_data(); storeContext.name = store.Name; storeContext.api_key = store.ApiKey; storeContext.url = store.Url; storeContext.interval = store.Interval; storeContext.last_run = DateTime.Now; storeContext.dateCreated = DateTime.Now; storeContext.dateModified = DateTime.Now; storeContext.isActive = 1; context.stores_data.AddObject(storeContext); context.SaveChanges(); return(storeContext.id); } catch (InvalidOperationException exc) { AccessConnectionHandler.log.Error(exc); return(0); } catch (ArgumentNullException exc) { AccessConnectionHandler.log.Error(exc); return(0); } catch (NullReferenceException exc) { AccessConnectionHandler.log.Error(exc); return(0); } catch (OptimisticConcurrencyException exc) { AccessConnectionHandler.log.Error(exc); return(0); } catch (UpdateException exc) { AccessConnectionHandler.log.Error(exc); return(0); } finally { context.Dispose(); } }
public bool RemoveStore(int id) { var context = new orderstatusEntities(); try { stores_data storeContext = context.stores_data.Where(x => x.id == id).SingleOrDefault(); if (storeContext != null) { storeContext.isActive = 0; context.SaveChanges(); } } catch (Exception ex) { log.Error("Error Exception: " + ex.Message); return(false); } finally { context.Dispose(); } return(true); }