Beispiel #1
0
        /// <summary>
        /// Save the measurement points for an implement.
        /// </summary>
        /// <param name="get_auto"></param>
        /// <param name="measurementPoints"></param>
        /// <returns>Result = 1 for successful save, Result = 0 for no save, Result = -1 for error.</returns>
        public int SaveMeasurementPoints(int get_auto, List <MeasurementPointDetails> measurementPoints)
        {
            int result        = 0;
            int _changesSaved = 0;

            using (var _context = new DAL.GETContext())
            {
                // Check if there are any records already for measurement points.
                var existingRecords = _context.GET_COMPONENT
                                      .Where(w => w.get_auto == get_auto && w.active == true)
                                      .ToList();

                // GET record
                var GT = _context.GET.Find(get_auto);

                if (existingRecords.Count != 0)
                {
                    for (int i = 0; i < measurementPoints.Count; i++)
                    {
                        var GETComponentRecord = existingRecords
                                                 .Where(w => w.get_component_auto == measurementPoints[i].Id)
                                                 .FirstOrDefault();

                        // Update the existing record.
                        if (GETComponentRecord != null)
                        {
                            GETComponentRecord.make_auto             = measurementPoints[i].Make != 0 ? measurementPoints[i].Make : (int?)null;
                            GETComponentRecord.observation_list_auto = measurementPoints[i].ObservationListId;
                            GETComponentRecord.req_measure           = ((measurementPoints[i].InitialLength) == 0 &&
                                                                        (measurementPoints[i].WornLength == 0)) ? false : true;
                            GETComponentRecord.initial_length = measurementPoints[i].InitialLength;
                            GETComponentRecord.worn_length    = measurementPoints[i].WornLength;
                            GETComponentRecord.part_no        = measurementPoints[i].PartNo;
                        }
                    }
                }

                // Save changes
                try
                {
                    _changesSaved = _context.SaveChanges();
                    if (_changesSaved > 0)
                    {
                        result = 1;
                    }
                }
                catch (Exception ex1)
                {
                    result = -1;
                }
            }

            return(result);
        }
Beispiel #2
0
        /// <summary>
        /// Save the observation points for an implement.
        /// </summary>
        /// <param name="get_auto"></param>
        /// <param name="observationPoints"></param>
        /// <returns>Result = 1 for successful save, Result = 0 for no save, Result = -1 for error.</returns>
        public int SaveObservationPoints(int get_auto, List <ObservationPointDetails> observationPoints)
        {
            int result        = 0;
            int _changesSaved = 0;

            using (var _context = new DAL.GETContext())
            {
                // Check if there are any existing records.
                var existingRecords = _context.GET_OBSERVATION_POINTS
                                      .Where(w => w.get_auto == get_auto && w.active == true)
                                      .ToList();

                if (existingRecords.Count != 0)
                {
                    for (int i = 0; i < observationPoints.Count; i++)
                    {
                        var gop = _context.GET_OBSERVATION_POINTS.Find(observationPoints[i].Id);

                        gop.observation_list = (observationPoints[i].ObservationListId != 0) ?
                                               observationPoints[i].ObservationListId : (int?)null;
                        gop.req_measure = ((observationPoints[i].InitialLength) == 0 &&
                                           (observationPoints[i].WornLength == 0)) ? false : true;
                        gop.initial_length = observationPoints[i].InitialLength;
                        gop.worn_length    = observationPoints[i].WornLength;
                    }
                }

                // Save changes
                try
                {
                    _changesSaved = _context.SaveChanges();
                    if (_changesSaved > 0)
                    {
                        result = 1;
                    }
                }
                catch (Exception ex1)
                {
                    result = -1;
                }
            }

            return(result);
        }
Beispiel #3
0
        /// <summary>
        /// Creates a new repairer for the customer at the specified jobsite.
        /// </summary>
        /// <param name="jobsiteId"></param>
        /// <param name="repairerName"></param>
        /// <returns></returns>
        public int CreateRepairer(long jobsiteId, string repairerName)
        {
            int result = 0;

            using (var dataEntities = new DAL.GETContext())
            {
                // Check that the customer exists.
                var jobsite = dataEntities.CRSF.Find(jobsiteId);
                if (jobsite != null)
                {
                    var customer = dataEntities.CUSTOMERs.Find(jobsite.customer_auto);
                    if (customer != null)
                    {
                        // Check that the repairer doesn't already exist.
                        var repairer = dataEntities.GET_REPAIRER
                                       .Where(r => r.name == repairerName)
                                       .FirstOrDefault();

                        if (repairer == null)
                        {
                            // Add new repairer.
                            DAL.GET_REPAIRER newRepairer = new DAL.GET_REPAIRER
                            {
                                name          = repairerName,
                                customer_auto = customer.customer_auto
                            };
                            dataEntities.GET_REPAIRER.Add(newRepairer);

                            int _changesSaved = dataEntities.SaveChanges();
                            if (_changesSaved > 0)
                            {
                                result = newRepairer.repairer_auto;
                            }
                        }
                    }
                }
            }

            return(result);
        }
Beispiel #4
0
        /// <summary>
        /// Creates a new workshop for the specified repairer.
        /// </summary>
        /// <param name="repairerId"></param>
        /// <param name="workshopName"></param>
        /// <returns></returns>
        public int CreateWorkshop(int repairerId, string workshopName)
        {
            int result = 0;

            using (var dataEntities = new DAL.GETContext())
            {
                // Check that the repairer exists.
                var repairer = dataEntities.GET_REPAIRER.Find(repairerId);
                if (repairer != null)
                {
                    // Check that the workshop doesn't already exist.
                    var workshop = dataEntities.GET_WORKSHOP
                                   .Where(w => w.name == workshopName)
                                   .FirstOrDefault();

                    if (workshop == null)
                    {
                        // Add new workshop.
                        DAL.GET_WORKSHOP newWorkshop = new DAL.GET_WORKSHOP
                        {
                            name          = workshopName,
                            repairer_auto = repairerId
                        };
                        dataEntities.GET_WORKSHOP.Add(newWorkshop);

                        int _changesSaved = dataEntities.SaveChanges();
                        if (_changesSaved > 0)
                        {
                            result = newWorkshop.workshop_auto;
                        }
                    }
                }
            }

            return(result);
        }
Beispiel #5
0
        /// <summary>
        /// Record a Component Replace action for a component in Inventory.
        /// </summary>
        /// <param name="componentId"></param>
        /// <param name="cost"></param>
        /// <param name="date"></param>
        /// <param name="comment"></param>
        /// <param name="authUserId"></param>
        /// <returns></returns>
        public bool RecordComponentReplace(int componentId, decimal cost, DateTime date, string comment, long authUserId)
        {
            bool result = false;

            using (var dataEntities = new DAL.GETContext())
            {
                int _changesSaved_GETEvent          = 0;
                int _changesSaved_ImplementEvent    = 0;
                int _changesSaved_NewComponent      = 0;
                int _changesSaved_OldComponentEvent = 0;
                int _changesSaved_NewComponentEvent = 0;

                DateTime recordedDate = DateTime.Now;

                var GETComponent = dataEntities.GET_COMPONENT.Find(componentId);

                // Create a new entry in GET_EVENTS.
                var GETEvent = eventManagement.createGETEvent(authUserId, (int)Core.Domain.GETActionType.Component_Replacement, date, comment, cost, recordedDate);
                dataEntities.GET_EVENTS.Add(GETEvent);
                _changesSaved_GETEvent = dataEntities.SaveChanges();

                // Create a new entry in GET_EVENTS_IMPLEMENT.
                if (_changesSaved_GETEvent > 0)
                {
                    if (GETComponent != null)
                    {
                        var previousImplementEvent = dataEntities.GET_EVENTS_IMPLEMENT
                                                     .Where(e => e.get_auto == GETComponent.get_auto)
                                                     .OrderByDescending(ie => ie.implement_events_auto)
                                                     .FirstOrDefault();
                        int previousImplementLTD = 0;
                        if (previousImplementEvent != null)
                        {
                            previousImplementLTD = previousImplementEvent.ltd;
                        }

                        var implementEvent = eventManagement.createImplementEvent(GETComponent.get_auto, previousImplementLTD, GETEvent.events_auto);
                        dataEntities.GET_EVENTS_IMPLEMENT.Add(implementEvent);
                        _changesSaved_ImplementEvent = dataEntities.SaveChanges();
                    }
                }

                // Create a new component entry.
                GET_COMPONENT newComponent = new GET_COMPONENT
                {
                    make_auto             = GETComponent.make_auto,
                    get_auto              = GETComponent.get_auto,
                    observation_list_auto = GETComponent.observation_list_auto,
                    cmu                      = 0,
                    install_date             = recordedDate,
                    ltd_at_setup             = 0,
                    req_measure              = GETComponent.req_measure,
                    initial_length           = GETComponent.initial_length,
                    worn_length              = GETComponent.worn_length,
                    price                    = cost,
                    part_no                  = GETComponent.part_no,
                    schematic_component_auto = GETComponent.schematic_component_auto,
                    active                   = true
                };
                dataEntities.GET_COMPONENT.Add(newComponent);
                _changesSaved_NewComponent = dataEntities.SaveChanges();

                // Mark the old component as inactive.
                if (_changesSaved_NewComponent > 0)
                {
                    GETComponent.active = false;
                    dataEntities.SaveChanges();
                }

                // Create an entry in GET_EVENTS_COMPONENT for the component being replaced.
                var oldComponentEvent = eventManagement.createComponentEvent(GETComponent.get_component_auto,
                                                                             GETComponent.cmu, GETEvent.events_auto, 1);
                dataEntities.GET_EVENTS_COMPONENT.Add(oldComponentEvent);
                _changesSaved_OldComponentEvent = dataEntities.SaveChanges();

                // Create an entry in GET_EVENTS_COMPONENT for the new component.
                var newComponentEvent = eventManagement.createComponentEvent(newComponent.get_component_auto,
                                                                             newComponent.cmu, GETEvent.events_auto, 0);
                dataEntities.GET_EVENTS_COMPONENT.Add(newComponentEvent);
                _changesSaved_NewComponentEvent = dataEntities.SaveChanges();

                if ((_changesSaved_GETEvent > 0) && (_changesSaved_OldComponentEvent > 0) &&
                    (_changesSaved_NewComponentEvent > 0) && (_changesSaved_ImplementEvent > 0))
                {
                    GETEvent.recordStatus = 0;
                    result = true;
                }
                else
                {
                    oldComponentEvent.recordStatus = 0;
                    newComponentEvent.recordStatus = 1;
                    GETEvent.recordStatus          = 1;
                }
                dataEntities.SaveChanges();
            }

            return(result);
        }
Beispiel #6
0
        /// <summary>
        /// Record a Component Repair action for a component in Inventory.
        /// </summary>
        /// <param name="componentId"></param>
        /// <param name="cost"></param>
        /// <param name="date"></param>
        /// <param name="comment"></param>
        /// <param name="authUserId"></param>
        /// <returns></returns>
        public bool RecordComponentRepair(int componentId, decimal cost, DateTime date, string comment, long authUserId)
        {
            bool result = false;

            using (var dataEntities = new DAL.GETContext())
            {
                int _changesSaved_GETEvent       = 0;
                int _changesSaved_ComponentEvent = 0;
                int _changesSaved_ImplementEvent = 0;

                // Create a new entry in GET_EVENTS.
                var GETEvent = eventManagement.createGETEvent(authUserId, (int)Core.Domain.GETActionType.Component_Repair, date, comment, cost);
                dataEntities.GET_EVENTS.Add(GETEvent);
                _changesSaved_GETEvent = dataEntities.SaveChanges();

                // Create a new entry in GET_EVENTS_COMPONENT.
                if (_changesSaved_GETEvent > 0)
                {
                    var previousComponentEvent = dataEntities.GET_EVENTS_COMPONENT
                                                 .Where(gc => gc.get_component_auto == componentId)
                                                 .OrderByDescending(ce => ce.component_events_auto)
                                                 .FirstOrDefault();
                    int previousComponentLTD = 0;
                    if (previousComponentEvent != null)
                    {
                        previousComponentLTD = previousComponentEvent.ltd;
                    }

                    var componentEvent = eventManagement.createComponentEvent(componentId, previousComponentLTD, GETEvent.events_auto, 0);
                    dataEntities.GET_EVENTS_COMPONENT.Add(componentEvent);
                    _changesSaved_ComponentEvent = dataEntities.SaveChanges();
                }

                // Create a new entry in GET_EVENTS_IMPLEMENT.
                if (_changesSaved_GETEvent > 0)
                {
                    var GETComponent = dataEntities.GET_COMPONENT.Find(componentId);
                    if (GETComponent != null)
                    {
                        var previousImplementEvent = dataEntities.GET_EVENTS_IMPLEMENT
                                                     .Where(e => e.get_auto == GETComponent.get_auto)
                                                     .OrderByDescending(ie => ie.implement_events_auto)
                                                     .FirstOrDefault();
                        int previousImplementLTD = 0;
                        if (previousImplementEvent != null)
                        {
                            previousImplementLTD = previousImplementEvent.ltd;
                        }

                        var implementEvent = eventManagement.createImplementEvent(GETComponent.get_auto, previousImplementLTD, GETEvent.events_auto);
                        dataEntities.GET_EVENTS_IMPLEMENT.Add(implementEvent);
                        _changesSaved_ImplementEvent = dataEntities.SaveChanges();
                    }
                }

                if ((_changesSaved_GETEvent > 0) && (_changesSaved_ComponentEvent > 0) &&
                    (_changesSaved_ImplementEvent > 0))
                {
                    GETEvent.recordStatus = 0;
                    result = true;
                }
                else
                {
                    GETEvent.recordStatus = 1;
                }
                dataEntities.SaveChanges();
            }

            return(result);
        }