public IActionResult GetEquipment(string id)
        {
            ViewModels.Equipment result = null;

            if (!string.IsNullOrEmpty(id) && Guid.TryParse(id, out Guid equipmentId))
            {
                // query the Dynamics system to get the Equipment record.
                MicrosoftDynamicsCRMbcgovEquipment equipment = _dynamicsClient.GetEquipmentByIdWithChildren(equipmentId);

                if (equipment != null)
                {
                    result = equipment.ToViewModel();
                }
                else
                {
                    return(new NotFoundResult());
                }
            }
            else
            {
                return(BadRequest());
            }

            return(Json(result));
        }
        public async Task <IActionResult> CreateEquipment(string applicationType, [FromBody] ViewModels.Equipment item)
        {
            // get UserSettings from the session
            string       temp         = _httpContextAccessor.HttpContext.Session.GetString("UserSettings");
            UserSettings userSettings = JsonConvert.DeserializeObject <UserSettings>(temp);

            // first check to see that a Equipment exists.
            string ApplicationSiteminderGuid = userSettings.SiteMinderGuid;

            if (ApplicationSiteminderGuid == null || ApplicationSiteminderGuid.Length == 0)
            {
                _logger.LogError(LoggingEvents.Error, "No Equipment Siteminder Guid exernal id");
                throw new Exception("Error. No ApplicationSiteminderGuid exernal id");
            }

            // create a new Equipment.
            MicrosoftDynamicsCRMbcgovEquipment equipment = new MicrosoftDynamicsCRMbcgovEquipment();

            equipment.CopyValues(item);

            try
            {
                equipment = await _dynamicsClient.Equipments.CreateAsync(equipment);
            }
            catch (OdataerrorException odee)
            {
                _logger.LogError("Error creating Equipment");
                _logger.LogError("Request:");
                _logger.LogError(odee.Request.Content);
                _logger.LogError("Response:");
                _logger.LogError(odee.Response.Content);
                throw new OdataerrorException("Error creating Equipment");
            }
            return(Json(equipment.ToViewModel()));
        }
 public static void CopyValues(this MicrosoftDynamicsCRMbcgovEquipment to, ViewModels.Equipment from)
 {
     // Equipment Information
     to.BcgovEquipmenttype      = (int?)from.EquipmentType;
     to.BcgovEquipmenttypeother = from.EquipmentTypeOther;
     to.BcgovName = from.Name;
     to.BcgovPillpressencapsulatorsize      = (int?)from.PillpressEncapsulatorSize;
     to.BcgovPillpressencapsulatorsizeother = from.PillpressEncapsulatorSizeOther;
     to.BcgovLevelofautomation    = (int?)from.LevelOfEquipmentAutomation;
     to.BcgovPillpressmaxcapacity = from.PillpressMaxCapacity;
     to.BcgovHowwasequipmentbuilt = (int?)from.HowWasEquipmentBuilt;
     // to.BcgovHowwasequipmentbuiltother = from.HowWasEquipmentBuiltOther;
     to.BcgovNameofmanufacturer = from.NameOfManufacturer;
     to.BcgovMake                             = from.EquipmentMake;
     to.BcgovModel                            = from.EquipmentModel;
     to.BcgovSerialnumber                     = from.SerialNumber;
     to.BcgovEncapsulatormaxcapacity          = from.EncapsulatorMaxCapacity;
     to.BcgovCustombuiltorkeypartserialnumber = from.CustomBuiltSerialNumber;
 }
        public async Task <IActionResult> UpdateEquipment([FromBody] ViewModels.Equipment item, string id)
        {
            if (!string.IsNullOrEmpty(id) && Guid.TryParse(id, out Guid equipmentId))
            {
                // get the Equipment
                MicrosoftDynamicsCRMbcgovEquipment equipment = _dynamicsClient.GetEquipmentByIdWithChildren(equipmentId);
                if (equipment == null)
                {
                    return(new NotFoundResult());
                }

                // get UserSettings from the session
                string       temp         = _httpContextAccessor.HttpContext.Session.GetString("UserSettings");
                UserSettings userSettings = JsonConvert.DeserializeObject <UserSettings>(temp);

                // Get the current account
                var account = _dynamicsClient.GetAccountByIdWithChildren(Guid.Parse(userSettings.AccountId));

                MicrosoftDynamicsCRMbcgovEquipment patchEquipment = new MicrosoftDynamicsCRMbcgovEquipment();
                patchEquipment.CopyValues(item);

                try
                {
                    await _dynamicsClient.Equipments.UpdateAsync(equipmentId.ToString(), patchEquipment);
                }
                catch (OdataerrorException odee)
                {
                    _logger.LogError("Error updating Equipment");
                    _logger.LogError("Request:");
                    _logger.LogError(odee.Request.Content);
                    _logger.LogError("Response:");
                    _logger.LogError(odee.Response.Content);
                }

                equipment = _dynamicsClient.GetEquipmentByIdWithChildren(equipmentId);
                return(Json(equipment.ToViewModel()));
            }
            else
            {
                return(BadRequest());
            }
        }
        /// <summary>
        /// Convert a given Incident to an Application ViewModel
        /// </summary>
        public static ViewModels.Equipment ToViewModel(this MicrosoftDynamicsCRMbcgovEquipment equipment)
        {
            ViewModels.Equipment result = null;
            if (equipment != null)
            {
                result = new ViewModels.Equipment()
                {
                    Id                             = equipment.BcgovEquipmentid,
                    EquipmentType                  = (Equipmenttype?)equipment.BcgovEquipmenttype,
                    EquipmentTypeOther             = equipment.BcgovEquipmenttypeother,
                    Name                           = equipment.BcgovName,
                    PillpressEncapsulatorSize      = (Pillpressencapsulatorsize?)equipment.BcgovPillpressencapsulatorsize,
                    PillpressEncapsulatorSizeOther = equipment.BcgovPillpressencapsulatorsizeother,
                    LevelOfEquipmentAutomation     = (Levelofequipmentautomation?)equipment.BcgovLevelofautomation,
                    PillpressMaxCapacity           = equipment.BcgovPillpressmaxcapacity,
                    HowWasEquipmentBuilt           = (Howwasequipmentbuilt?)equipment.BcgovHowwasequipmentbuilt,
                    // HowWasEquipmentBuiltOther = equipment.BcgovHowwasequipmentbuiltother,
                    NameOfManufacturer      = equipment.BcgovNameofmanufacturer,
                    EquipmentMake           = equipment.BcgovMake,
                    EquipmentModel          = equipment.BcgovModel,
                    SerialNumber            = equipment.BcgovSerialnumber,
                    EncapsulatorMaxCapacity = equipment.BcgovEncapsulatormaxcapacity,
                    CustomBuiltSerialNumber = equipment.BcgovCustombuiltorkeypartserialnumber,
                };

                // business profile (account)
                if (equipment.BcgovCurrentBusinessOwner != null)
                {
                    result.BcgovCurrentBusinessOwner = equipment.BcgovCurrentBusinessOwner.ToViewModel();
                }

                // current location
                if (equipment.BcgovCurrentLocation != null)
                {
                    result.BcgovCurrentLocation = equipment.BcgovCurrentLocation.ToViewModel();
                }
            }
            return(result);
        }
Beispiel #6
0
        /// <summary>
        /// Convert a given Incident to an Application ViewModel
        /// </summary>
        public static ViewModels.Equipment ToViewModel(this MicrosoftDynamicsCRMbcgovEquipment equipment)
        {
            string changeme = "changeme";

            ViewModels.Equipment result = null;
            if (equipment != null)
            {
                result = new ViewModels.Equipment()
                {
                    Id                                      = equipment.BcgovEquipmentid,
                    EquipmentType                           = changeme,
                    EquipmentTypeOther                      = changeme,
                    LevelOfEquipmentAutomation              = changeme,
                    PillpressEncapsulatorSize               = changeme,
                    PillpressEncapsulatorSizeOtherCheck     = changeme,
                    PillpressEncapsulatorSizeOther          = changeme,
                    PillpressMaxCapacity                    = changeme,
                    EncapsulatorMaxCapacity                 = changeme,
                    ExplanationOfEquipmentUse               = changeme,
                    HowWasEquipmentBuilt                    = changeme,
                    HowWasEquipmentBuiltOtherCheck          = changeme,
                    HowWasEquipmentBuiltOther               = changeme,
                    NameOfManufacturer                      = changeme,
                    EquipmentMake                           = changeme,
                    EquipmentModel                          = changeme,
                    SerialNumber                            = changeme,
                    HowEquipmentBuiltDescription            = changeme,
                    PersonBusinessThatBuiltEquipment        = changeme,
                    AddressPersonBusinessThatBuiltEquipment = changeme,
                    SerialNumberForCustomBuilt              = changeme,
                    CustomBuiltSerialNumber                 = changeme,
                    SerialNumberKeyPartDescription          = changeme,
                    OwnedBeforeJan2019                      = changeme,
                    PurchasedFromBcSeller                   = changeme,
                    PurchasedFromSellerOutsideofBc          = changeme,
                    ImportedToBcByAThirdParty               = changeme,
                    alternativeOwnershipArrangement         = changeme,
                    IAssembledItMyself                      = changeme,
                    HowCameIntoPossessionOtherCheck         = changeme,
                    HowCameIntoPossessionOther              = changeme,
                    NameOfBcSeller                          = changeme,
                    BCSellersAddress                        = changeme,
                    BcSellersContactPhoneNumber             = changeme,
                    BcSellersContactEmail                   = changeme,
                    Dateofpurchasefrombcseller              = changeme,
                    BcSellersRegistrationNumber             = changeme,
                    OutsideBcSellersName                    = changeme,
                    OutsideBCSellersAddress                 = changeme,
                    OutsideBcSellersLocation                = changeme,
                    DateOfPurchaseFromOutsideBcSeller       = changeme,
                    NameOfImporter                          = changeme,
                    ImportersAddress                        = changeme,
                    ImportersRegistrationNumber             = changeme,
                    nameoforiginatingseller                 = changeme,
                    OriginatingSellersAddress               = changeme,
                    OriginatingSellersLocation              = changeme,
                    DateOfPurchaseFromImporter              = changeme,
                    PossessUntilICanSell                    = changeme,
                    GiveNorLoanedToMe                       = changeme,
                    RentingOrLeasingFromAnotherBusiness     = changeme,
                    KindOfAlternateOwnershipOtherCheck      = changeme,
                    KindOfAlternateOwnershipOther           = changeme,
                    UsingToManufactureAProduct              = changeme,
                    AreYouARegisteredSeller                 = changeme,
                    NameOfBusinessThatHasGivenOrLoaned      = changeme,
                    AddressofBusinessthathasGivenorLoaned   = changeme,
                    PhoneOfBusinessThatHasGivenOrLoaned     = changeme,
                    EmailOfTheBusinessThatHasGivenOrLoaned  = changeme,
                    WhyAHaveYouAcceptedOrBorrowed           = changeme,
                    NameOfBusinessThatHasRentedOrLeased     = changeme,
                    AddressofBusinessThatHasRentedorLeased  = changeme,
                    PhoneOfBusinessThatHasRentedOrLeased    = changeme,
                    EmailOfBusinessThatHasRentedOrLeased    = changeme,
                    WhyHaveYouRentedOrLeased                = changeme,
                    WhenDidYouAssembleEquipment             = changeme,
                    WhereDidYouObtainParts                  = changeme,
                    DoYouAssembleForOtherBusinesses         = changeme,
                    DetailsOfAssemblyForOtherBusinesses     = changeme,
                    DetailsOfHowEquipmentCameIntoPossession = changeme,
                    DeclarationOfCorrectInformation         = changeme,
                    ConfirmationOfAuthorizedUse             = changeme,
                };
            }
            return(result);
        }
Beispiel #7
0
 public static void CopyValues(this MicrosoftDynamicsCRMbcgovEquipment to, ViewModels.Equipment from)
 {
     // Equipment Information
 }