Exemplo n.º 1
0
        /// <summary>
        /// convert shipment term view model to domain
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public ShipmentTerm ConvertToDomain(ShipmentTermViewModel model)
        {
            ShipmentTerm term = new ShipmentTerm();

            term.ShipmentTermId = model.ShipmentTermId;
            term.Description    = model.ShipmentTermDescription;
            term.IsActive       = model.IsActive;

            return(term);
        }
Exemplo n.º 2
0
        /// <summary>
        /// convert shipment term to view model
        /// </summary>
        /// <param name="term"></param>
        /// <returns></returns>
        public ShipmentTermViewModel ConvertToView(ShipmentTerm term)
        {
            ShipmentTermViewModel model = new ShipmentTermViewModel();

            model.ShipmentTermId          = term.ShipmentTermId;
            model.ShipmentTermDescription = (!string.IsNullOrEmpty(term.Description)) ? term.Description : "N/A";
            model.IsActive = term.IsActive;

            return(model);
        }
Exemplo n.º 3
0
        /// <summary>
        /// get shipment term by nullable id
        /// </summary>
        /// <param name="shipmentTermId"></param>
        /// <returns></returns>
        public ShipmentTerm GetShipmentTerm(Guid?shipmentTermId)
        {
            var shipmentTerm = new ShipmentTerm();

            try
            {
                shipmentTerm = _db.ShipmentTerm.FirstOrDefault(x => x.ShipmentTermId == shipmentTermId);
            }
            catch (Exception ex)
            {
                logger.ErrorFormat("Error getting shipment term: {0} ", ex.ToString());
            }

            return(shipmentTerm);
        }
Exemplo n.º 4
0
        /// <summary>
        /// update shipment term
        /// </summary>
        /// <param name="shipmentTerm"></param>
        /// <returns></returns>
        public OperationResult UpdateShipmentTerm(ShipmentTerm shipmentTerm)
        {
            var operationResult = new OperationResult();

            var existingShipmentTerm = GetShipmentTerm(shipmentTerm.ShipmentTermId);

            if (existingShipmentTerm != null)
            {
                logger.Debug("ShipmentTerm is being updated.");

                try
                {
                    _db.ShipmentTerm.Attach(existingShipmentTerm);

                    _db.Entry(existingShipmentTerm).CurrentValues.SetValues(shipmentTerm);

                    _db.SaveChanges();

                    operationResult.Success = true;
                    operationResult.Message = "Success";
                }
                catch (Exception ex)
                {
                    operationResult.Success = false;
                    operationResult.Message = "Error";
                    logger.ErrorFormat("Error while updating shipment term: { 0} ", ex.ToString());
                }
            }
            else
            {
                operationResult.Success = false;
                operationResult.Message = "Unable to find selected shipment term.";
            }

            return(operationResult);
        }
Exemplo n.º 5
0
        /// <summary>
        /// save shipment term
        /// </summary>
        /// <param name="newShipmentTerm"></param>
        /// <returns></returns>
        public OperationResult SaveShipmentTerm(ShipmentTerm newShipmentTerm)
        {
            var operationResult = new OperationResult();

            try
            {
                var existingShipmentTerm = _db.ShipmentTerm.FirstOrDefault(x => x.Description.ToLower() == newShipmentTerm.Description.ToLower());

                if (existingShipmentTerm == null)
                {
                    logger.Debug("ShipmentTerm is being created...");

                    newShipmentTerm.IsActive = true;

                    _db.ShipmentTerm.Add(newShipmentTerm);

                    _db.SaveChanges();

                    operationResult.Success = true;
                    operationResult.Message = "Success";
                }
                else
                {
                    operationResult.Success = false;
                    operationResult.Message = "Duplicate Entry";
                }
            }
            catch (Exception ex)
            {
                operationResult.Success = false;
                operationResult.Message = "Error";
                logger.ErrorFormat("Error saving new shipment term: {0} ", ex.ToString());
            }

            return(operationResult);
        }