public IActionResult Add([FromBody] Installation installation)
        {
            // convert the installation status to DbModel installation status
            var dbInstallationStatus = helper.ConvertToDbModelStatus(installation.Status);

            var dbModel = new DbModels.Installation();

            dbModel.InstallationID = installation.InstallationID;
            dbModel.MIRN           = installation.MIRN;
            dbModel.StreetNo       = installation.StreetNo;
            dbModel.StreetName     = installation.StreetName;
            dbModel.Suburb         = installation.Suburb;
            dbModel.State          = installation.State;
            dbModel.PostCode       = installation.PostCode;
            dbModel.Status         = dbInstallationStatus;

            var result = _repo.Add(dbModel);

            if (result.Equals("-1"))
            {
                return(NotFound());
            }
            else
            {
                return(Ok(result));
            }
        }
        public IActionResult Update(int id, [FromBody] Installation installation)
        {
            // getting Pay roll ID, Installation
            var installationByID = _repo.Get(id);

            if (installationByID == null)
            {
                return(NotFound());
            }
            else
            {
                // convert the installation status to DbModel installation status
                var dbInstallationStatus = helper.ConvertToDbModelStatus(installation.Status);

                var dbModel = new DbModels.Installation();

                dbModel.MIRN       = installation.MIRN;
                dbModel.StreetNo   = installation.StreetNo;
                dbModel.StreetName = installation.StreetName;
                dbModel.Suburb     = installation.Suburb;
                dbModel.State      = installation.State;
                dbModel.PostCode   = installation.PostCode;
                dbModel.Status     = dbInstallationStatus;

                var result = _repo.Update(id, dbModel);
                if (result.Equals("-1"))
                {
                    return(NotFound());
                }
                else
                {
                    return(Ok(result));
                }
            }
        }
        // Create return history method which return's either error message or success message
        public Tuple <bool, string> CreateInstallHistory(InstallationRequest iHistory)
        {
            var result = Tuple.Create(true, "");

            // validating Meter ID
            var meter = _mrepo.Get(iHistory.MIRN);

            if (meter.MIRN == null)
            {
                return(Tuple.Create(false, "Meter ID " + iHistory.MIRN + " is not found"));
            }

            // validating PayRoll ID
            var user = _urepo.Get(iHistory.PayRollID);

            if (user.PayRollID == null)
            {
                return(Tuple.Create(false, "PayRollID " + iHistory.PayRollID + " is not found"));
            }

            // validating meter status and meter condition
            // Return = 5, then actual meter status must be in Pickup
            if (!(meter.MeterStatus.Equals(DbModels.MeterStatus.Pickup)))
            {
                return(Tuple.Create(false, "Meter ID " + iHistory.MIRN + " is not available for install, current status is " + meter.MeterStatus));
            }

            if (!(meter.MeterCondition.Equals(DbModels.MeterCondition.Active)))
            {
                return(Tuple.Create(false, "Meter ID " + iHistory.MIRN + " is not available for install, current condition is " + meter.MeterCondition));
            }


            // validating not future date
            if (iHistory.TransactionDate > DateTime.UtcNow)
            {
                return(Tuple.Create(false, "Date should not be in the future date"));
            }

            // All validation are passed now converting the viewmodel to installation dbmodel
            var iDbModel = new DbModels.Installation();

            iDbModel.MIRN       = iHistory.MIRN;
            iDbModel.StreetNo   = iHistory.StreetNo;
            iDbModel.StreetName = iHistory.StreetName;
            iDbModel.Suburb     = iHistory.Suburb;
            iDbModel.State      = iHistory.State;
            iDbModel.PostCode   = iHistory.PostCode;
            iDbModel.Status     = DbModels.Status.Active;

            var iResult = _irepo.Add(iDbModel);

            if (iResult > 0)
            {
                //All validation are passed now converting the viewmodel to dbmodel
                var mhDbModel = new DbModels.MeterHistory();
                mhDbModel.MIRN            = iHistory.MIRN;
                mhDbModel.PayRollID       = iHistory.PayRollID;
                mhDbModel.MeterStatus     = DbModels.MeterStatus.Install;
                mhDbModel.Location        = Convert.ToString(iResult);
                mhDbModel.TransactionDate = iHistory.TransactionDate;
                mhDbModel.Comment         = iHistory.Comment;

                // creating meter history record in the DB
                var mhID = Add(mhDbModel);

                if (mhID > 0)
                {
                    return(Tuple.Create(true, mhID.ToString()));
                }
            }
            else
            {
                return(Tuple.Create(false, "Unable to create new Installation record!"));
            }
            return(Tuple.Create(false, "Unable to Install Meter!"));
        }