public ActionResult EditLinkedSettingTypes(EditLinkedSettingTypesViewModel vmEditLinks)
 {
     try
     {
         if (ModelState.IsValid)
         {
             /*
              * foreach (var atstLink in vmEditLinks.LinkedAssetTypeSettingTypes)
              * {
              *  // transfer vm to dto
              *  var dtoAssetTypeSettingType = _unitOfWork.AssetTypesSettingTypes.Get(atstLink.Id);
              *  if (dtoAssetTypeSettingType != null)
              *  {
              *      // update dto
              *      dtoAssetTypeSettingType.IsActive = atstLink.IsActive;
              *  }
              *  else if(atstLink.Id == 0)
              *  {
              *      // create new dto
              *      _unitOfWork.AssetTypesSettingTypes.Add(new Core.Models.AssetTypeSettingType()
              *      {
              *          AssetTypeId = atstLink.AssetTypeId,
              *          SettingTypeId = atstLink.SettingTypeId,
              *          IsActive = true
              *      });
              *  }
              * }
              *
              * // complete db update
              * _unitOfWork.CommitTrans();
              */
             // display view with message
             TempData["SuccessMessage"] = "Linked setting types updated.";
             return(RedirectToAction("Details", "AssetType", new { id = vmEditLinks.AssetTypeId }));
         }
         TempData["ErrorMessage"] = "Unable to edit record. Try again.";
         return(RedirectToAction("Index", "AssetType"));
     }
     catch (Exception)
     {
         TempData["ErrorMessage"] = "Encountered problem";
         return(RedirectToAction("Index", "AssetType"));
     }
 }
Example #2
0
        public ActionResult Edit(EditLinkedSettingTypesViewModel vmEditLinkedSettingTypes)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    // transfer vm to dto
                    foreach (var vmEdit in vmEditLinkedSettingTypes.EditViewModels)
                    {
                        // new entry?
                        if (vmEdit.Id == 0)
                        {
                            // YES. Create record
                            _unitOfWork.AssetSettings.Add(new AssetSetting()
                            {
                                AssetId       = vmEditLinkedSettingTypes.AssetId,
                                SettingTypeId = vmEdit.SettingTypeId,
                                Value         = vmEdit.Value,
                                IsActive      = true
                            });
                        }
                        else
                        {
                            var dtoAssetSetting = _unitOfWork.AssetSettings.Get(vmEdit.Id);
                            dtoAssetSetting.Value = vmEdit.Value;
                        }
                    }

                    // update db
                    _unitOfWork.CommitTrans();

                    // display view with message
                    TempData["SuccessMessage"] = "Records updated";
                    return(RedirectToAction("Details", "Asset", new { id = vmEditLinkedSettingTypes.AssetId }));
                }
                TempData["ErrorMessage"] = "Unable to edit record. Try again.";
                return(RedirectToAction("Index", "Asset"));
            }
            catch (Exception)
            {
                TempData["ErrorMessage"] = "Encountered Problem";
                return(RedirectToAction("Index", "Asset"));
            }
        }