public ResponseApiViewModel SetPricesByContract(PricesByContractViewModel pricesByContract)
        {
            try
            {
                using (DB_FleetServiceEntities db = new DB_FleetServiceEntities())
                {
                    ResponseApiViewModel rta = new ResponseApiViewModel();
                    string transactionType   = "";
                    int    contract_id       = (int)pricesByContract.contract.id;
                    var    lsOldPrices       = db.PricesByContract.Where(pbc => pbc.cntr_id == pricesByContract.contract.id).ToList();

                    IEnumerable <MaintenanceItemViewModel> lsNewItems = from lsItems in pricesByContract.lsMaintenanceItems
                                                                        where !lsOldPrices.Any(itm => itm.mi_id == lsItems.id)
                                                                        select lsItems;

                    if (lsOldPrices.Count > 0)
                    {
                        foreach (var oldPrice in lsOldPrices)
                        {
                            var newPrice = pricesByContract.lsMaintenanceItems.Find(it => it.id == oldPrice.mi_id);

                            if (oldPrice.mi_referencePrice != newPrice.referencePrice)
                            {
                                transactionType = "UPDATE";
                                PricesByContract priceByContract = db.PricesByContract.Where(pbc => pbc.pbc_id == oldPrice.pbc_id).FirstOrDefault();
                                this.setDataPricesByContract(contract_id, (int)oldPrice.mi_id, (float)newPrice.referencePrice, transactionType, ref priceByContract);
                                db.SaveChanges();
                            }

                            foreach (var item in lsNewItems)
                            {
                                PricesByContract priceByContract = new PricesByContract();
                                this.setDataPricesByContract((int)pricesByContract.contract.id, (int)item.id, (float)item.referencePrice, "INSERT", ref priceByContract);
                                db.PricesByContract.Add(priceByContract);
                                db.SaveChanges();
                            }
                        }
                    }
                    else
                    {
                        transactionType = "INSERT";
                        foreach (var item in pricesByContract.lsMaintenanceItems)
                        {
                            PricesByContract priceByContract = new PricesByContract();
                            this.setDataPricesByContract(contract_id, (int)item.id, (float)item.referencePrice, transactionType, ref priceByContract);
                            db.PricesByContract.Add(priceByContract);
                            db.SaveChanges();
                        }
                    }

                    rta.response = true;
                    rta.message  = "Se han asignado los precios del contrato: " + pricesByContract.contract.code;
                    return(rta);
                }
            }
            catch (Exception ex)
            {
                return(null);
            }
        }
        private void setDataPricesByContract(int contract_id, int maintenanceItem_id, float referencePrice, string transacctionType, ref PricesByContract priceByContract)
        {
            priceByContract.cntr_id           = contract_id;
            priceByContract.mi_id             = maintenanceItem_id;
            priceByContract.mi_referencePrice = referencePrice;

            if (transacctionType == "INSERT")
            {
                priceByContract.pbc_registrationDate = DateTime.Now;
            }

            if (transacctionType == "UPDATE")
            {
                priceByContract.pbc_updateDate = DateTime.Now;
            }
        }