Exemplo n.º 1
0
        public WorkOrder Update(WorkOrder workorder)
        {
            var       context    = new CammContext();
            WorkOrder targetItem = context.WorkOrders.Find(workorder.WoNumber);

            if (targetItem != null)
            {
                targetItem.AssemblyNumber       = workorder.AssemblyNumber;
                targetItem.Customer             = workorder.Customer;
                targetItem.CustomerPO           = workorder.CustomerPO;
                targetItem.DueDate              = workorder.DueDate;
                targetItem.QuantityToBuild      = workorder.QuantityToBuild;
                targetItem.SalesOrder           = workorder.SalesOrder;
                targetItem.SalesOrderLineItemNo = workorder.SalesOrderLineItemNo;
                targetItem.WoStatus             = workorder.WoStatus;
                targetItem.TimeStamp            = DateTime.Now;
            }
            else
            {
                throw new Exception("WorkOrder with WoNumber " + workorder.WoNumber + " not found.");
            }

            context.SaveChanges();
            return(targetItem);
        }
Exemplo n.º 2
0
        public WorkOrder Add(WorkOrder workOrder)
        {
            var context      = new CammContext();
            var keyViolation = context.WorkOrders.Find(workOrder.WoNumber);

            if (keyViolation != null)
            {
                throw new Exception("Duplicate WoNumber");
            }
            var WO = context.WorkOrders.Add(workOrder);

            try
            {
                var result = context.SaveChanges();
                if (result == 1)
                {
                    return(WO);
                }
                else
                {
                    throw new Exception("Save failed for an unknown reason.");
                };
            }
            catch (Exception ex)
            {
                throw new Exception("Save failed. " + ex.InnerException.InnerException);
            }
        }
Exemplo n.º 3
0
        public int Remove(string woNumber)
        {
            var       context  = new CammContext();
            WorkOrder unwanted = context.WorkOrders.Find(woNumber);

            try
            {
                context.WorkOrders.Remove(unwanted);
                var result = context.SaveChanges();
                return(result);
            }
            catch (Exception)
            {
                return(0);
            }
        }