internal bool DeleteItem(int Id) { OpCoDivision opcoDivision = new OpCoDivision(); opcoDivision.Id = Id; return(OpcoDivisionController.DeleteOpCoDivision(opcoDivision)); }
/// <summary> /// Saves an OpCo Division object. /// </summary> /// <remarks>If the Id property =0 then an INSERT will Occur, otherwise an UPDATE will occur</remarks> /// <param name="opcoDivision">The opco.</param> /// <returns></returns> public static int SaveOpCoDivision(OpCoDivision opcoDivision) { try { if (opcoDivision.IsValid) { // Save entity opcoDivision.Id = DataAccessProvider.Instance().SaveOpCoDivision(opcoDivision); if (opcoDivision.Id != -1) { FrameworkController.GetChecksum(opcoDivision); CacheManager.Add(opcoDivision, opcoDivision.OpCo != null); } } else { // Entity is not valid throw new InValidBusinessObjectException(opcoDivision); } } catch (Exception ex) { if (ExceptionPolicy.HandleException(ex, "Business Logic")) { throw; } } // Done return(opcoDivision.Id); }
/// <summary> /// Fullies the populate. /// </summary> /// <param name="fullyPopulate">if set to <c>true</c> [fully populate].</param> /// <param name="dataAccessProvider">The data access provider.</param> /// <param name="opcoDivision">The opco division.</param> private static void PopulateDivision(OpCoDivision opcoDivision, IDataReader dataReader, bool fullyPopulate) { if (fullyPopulate && opcoDivision != null) { opcoDivision.OpCo = OpcoController.GetOpCo(opcoDivision.OpCoId, true); } }
/// <summary> /// Gets a single OpCo Division for the specified Id. /// </summary> /// <param name="opcoDivisionId">The opco division id.</param> /// <param name="fullyPopulate">if set to <c>true</c> [fully populate].</param> /// <returns></returns> public static OpCoDivision GetOpCoDivision(int opcoDivisionId, bool fullyPopulate) { OpCoDivision opcoDivision = null; try { opcoDivision = CacheManager.Get <OpCoDivision>(opcoDivisionId, fullyPopulate); if (opcoDivision == null || opcoDivision.Logo == null) { opcoDivision = CBO <OpCoDivision> .FillObject(DataAccessProvider.Instance().GetOpCoDivision(opcoDivisionId), PopulateDivision, fullyPopulate); if (opcoDivision != null) { CacheManager.Add(opcoDivision); } } } catch (Exception ex) { // Log and throw exception if (ExceptionPolicy.HandleException(ex, "Business Logic")) { throw; } } return(opcoDivision); }
public static OpCoDivision PopulateNewItem() { OpCoDivision opCoDivision = new OpCoDivision(); opCoDivision.Code = Guid.NewGuid().ToString().Substring(0, 3); opCoDivision.Logo = new byte[1]; opCoDivision.LogoURI = "uri"; opCoDivision.OpCo = OpcoTests.PopulateNewItem(); opCoDivision.OpCoId = OpcoTests.SaveItem(opCoDivision.OpCo); opCoDivision.UpdatedBy = "test"; return(opCoDivision); }
public void SaveOpCoDivisionTestConstraint() { using (TransactionScope scope = new TransactionScope()) { //get a new item OpCoDivision opCoDivision = PopulateNewItem(); //save the item SaveItem(opCoDivision); //save the item again, because it's id still =-1 then another insert will occur and because the item //has the same code a constraint will be violated SaveItem(opCoDivision); } }
public void UpdateItem() { using (TransactionScope scope = new TransactionScope()) { OpCoDivision item = PopulateNewItem(); item.Id = SaveItem(item); item = GetItem(item.Id, true); //change a value string newCode = Guid.NewGuid().ToString().Substring(0, 3); item.Code = newCode; SaveItem(item); item = GetItem(item.Id, true); Assert.IsTrue(item.Code == newCode); } }
public void ConcurrencyTest() { using (TransactionScope ts = new TransactionScope()) { try { OpCoDivision item = PopulateNewItem(); item.Id = SaveItem(item); //change a value item.Code = Guid.NewGuid().ToString().Substring(0, 3); SaveItem(item); } catch (DiscoveryException e) { Assert.IsInstanceOfType(typeof(ConcurrencyException), e.InnerException); throw e; } } }
/// <summary> /// Deletes a OpCo Division. /// </summary> /// <param name="opcoDivision">The opco Division to delete.</param> /// <returns>Success state</returns> public static bool DeleteOpCoDivision(OpCoDivision opcoDivision) { bool success = false; try { if (opcoDivision != null) { success = DataAccessProvider.Instance().DeleteOpCoDivision(opcoDivision.Id); if (success) { CacheManager.Remove(opcoDivision); } } } catch (Exception ex) { if (ExceptionPolicy.HandleException(ex, "Business Logic")) { throw; } } return(success); }
static internal TDCShipment PopulateItem() { TDCShipment tdcShipment = new TDCShipment(); OpCoShipment opCoShipment = OpcoShipmentTests.PopulateNewItem(); try { tdcShipment.OpCoShipmentId = OpCoShipmentController.SaveShipment(opCoShipment); } catch (InValidBusinessObjectException e) { Console.Write(e.ValidatableObject.ValidationMessages); } tdcShipment.OpCoCode = opCoShipment.OpCoCode; tdcShipment.OpCoSequenceNumber = 1; tdcShipment.OpCoContact.Email = "Email"; tdcShipment.OpCoContact.Name = "Name"; tdcShipment.DespatchNumber = "Number"; tdcShipment.RequiredShipmentDate = DateTime.Now; tdcShipment.CustomerNumber = "CustNo"; tdcShipment.CustomerName = "CustomerName"; tdcShipment.CustomerReference = "ref"; tdcShipment.CustomerAddress.Line1 = "Line1"; tdcShipment.CustomerAddress.PostCode = "NN8 1NB"; tdcShipment.ShipmentNumber = "ShipNo"; tdcShipment.ShipmentName = "ShipmentName"; tdcShipment.ShipmentAddress.Line1 = "Line1"; tdcShipment.ShipmentAddress.PostCode = "NN8 1NB"; tdcShipment.SalesBranchCode = "BranchCode"; tdcShipment.AfterTime = "11:11"; tdcShipment.BeforeTime = "10:10"; tdcShipment.TailLiftRequired = false; tdcShipment.CheckInTime = 1; tdcShipment.DivisionCode = "Div"; tdcShipment.GeneratedDateTime = DateTime.Now; tdcShipment.Status = Shipment.StatusEnum.Mapped; tdcShipment.IsRecurring = false; tdcShipment.IsValidAddress = false; tdcShipment.PAFAddress.Line1 = "Line1"; tdcShipment.PAFAddress.PostCode = "PostCode"; tdcShipment.UpdatedBy = "UpdatedBy"; tdcShipment.Instructions = "Instructions"; tdcShipment.VehicleMaxWeight = (decimal)1.1; OpCoDivision division = OpcoDivisionTests.PopulateNewItem(); OpcoDivisionTests.SaveItem(division); tdcShipment.DivisionCode = division.Code; Warehouse deliveryWarehouse = WarehouseTests.PopulateNewItem(); WarehouseTests.SaveItem(deliveryWarehouse); tdcShipment.DeliveryWarehouseCode = deliveryWarehouse.Code; Warehouse stockWarehouse = WarehouseTests.PopulateNewItem(); WarehouseTests.SaveItem(stockWarehouse); tdcShipment.StockWarehouseCode = stockWarehouse.Code; Route route = RouteTests.PopulateNewItem(); RouteTests.SaveItem(route); tdcShipment.RouteCode = route.Code; TransactionType transactionType = TransactionTypeTests.PopulateNewItem(); TransactionTypeTests.SaveItem(transactionType); tdcShipment.TransactionTypeCode = transactionType.Code; TransactionSubType transactionSubType = TransactionSubTypeTests.PopulateNewItem(); TransactionSubTypeTests.SaveItem(transactionSubType); tdcShipment.TransactionSubTypeCode = transactionSubType.Code; return(tdcShipment); }
public static int SaveItem(OpCoDivision opCoDivision) { return(OpcoDivisionController.SaveOpCoDivision(opCoDivision)); }