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) { return dto; 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 int EditStore(StoreDto store) { var context = new orderstatusEntities(); try { var storeContext = context.stores_data.Where(x => x.id == store.Id).SingleOrDefault(); if (storeContext != null) { storeContext.name = store.Name; storeContext.api_key = store.ApiKey; storeContext.url = store.Url; storeContext.interval = store.Interval; storeContext.dateModified = DateTime.Now; storeContext.isActive = 1; context.SaveChanges(); } var orderStatus = context.order_status_by_store.Where(x => x.storeid == store.Id).ToList(); foreach (var orderStatusByStore in orderStatus) { context.order_status_by_store.DeleteObject(orderStatusByStore); context.SaveChanges(); } var customShips = context.custom_shipments.Where(x => x.storeId == store.Id).ToList(); foreach (var customShipmentse in customShips) { context.custom_shipments.DeleteObject(customShipmentse); context.SaveChanges(); } return store.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 ActionResult AddStore(StoreModels store) { _stores = new Stores(); if (ModelState.IsValid) { if (!Utilities.RegularExpressions.UrlIsValid(store.Url)) { ModelState.AddModelError("URL", "Invalid Url"); store.IntervalList = GenerateSelectListItems(intervalsList, store.DefaultInterval); store.OrderStatus = _stores.GetPublicOrdersStatus(); return View(store); } if (!Utilities.RegularExpressions.ApiKeyIsvalid(store.ApiKey)) { store.IntervalList = GenerateSelectListItems(intervalsList, store.DefaultInterval); store.OrderStatus = _stores.GetPublicOrdersStatus(); ModelState.AddModelError("ApiKey", "The API KEY must be a 32 characters long and ONLY numbers"); return View(store); } string[] CharList = Request.Form["rdOrderStatus"].Split(','); if (CharList.Length == 0 && store.CustomOrderStatus.Equals("")) { store.IntervalList = GenerateSelectListItems(intervalsList, store.DefaultInterval); store.OrderStatus = _stores.GetPublicOrdersStatus(); ModelState.AddModelError("OrderStatus", "You need to select at least one Order Status or create your custom one"); return View(store); } List<string> orderStatusList = new List<string>(); foreach (string item in CharList) { orderStatusList.Add(item); } StoreDto storeDto = new StoreDto(); storeDto.Name = store.StoreName; storeDto.ApiKey = store.ApiKey; storeDto.Url = store.Url; storeDto.Interval = int.Parse(store.DefaultInterval); string customOrderStatus = ""; if (store.CustomOrderStatus != null && !store.CustomOrderStatus.Equals("")) { string[] customStatuses = store.CustomOrderStatus.Split(';'); foreach (var stat in customStatuses) { customOrderStatus = _stores.AddCustomOrderStatus(stat).ToString(); if (!customOrderStatus.Equals("")) { orderStatusList.Add(customOrderStatus); } customOrderStatus = ""; } } int storeId = _stores.AddStore(storeDto); if (storeId != 0) { _stores.AddOrderStatusByStoreId(orderStatusList, storeId); List<string> customShipments = new List<string>(); if (store.CustomShip1 != null && !store.CustomShip1.Equals("")) { customShipments.Add(store.CustomShip1); } if (store.CustomShip2 != null && !store.CustomShip2.Equals("")) { customShipments.Add(store.CustomShip2); } if (store.CustomShip3 != null && !store.CustomShip3.Equals("")) { customShipments.Add(store.CustomShip3); } if (customShipments.Count>0) { _stores.CreateCustomShipments(customShipments,storeId); } return RedirectToAction("Index", "Store"); } return RedirectToAction("Index", "Store"); } else { store.IntervalList = GenerateSelectListItems(intervalsList, store.DefaultInterval); store.OrderStatus = _stores.GetPublicOrdersStatus(); return View(store); } }