Как я могу преодолеть эту ошибку CS1579 в ASP. net? - PullRequest
1 голос
/ 15 января 2020

Ошибка отображается следующим образом:

System.Web.HttpCompileException: 'C: \ Users \ MEDADUWA \ source \ repos \ CapeXPro \ CapeXPro \ Views \ FAWizard_AddAsset.cs html (43): ошибка CS1579: оператор foreach не может работать с переменными типа «FAInfo», поскольку «FAInfo» не содержит определения publi c для «GetEnumerator» *

Моя ViewModel :

namespace DAL.Entities
{
    public class FAInfo
    {
        public int WizardId { get; set; }
        public string WizardType { get; set; }

        public Step2 Step2 { get; set; }

        public List<Step2> ListStep2 { get; set; }

        public int Status { get; set; }
    }

    public class Step2
    {
        public int assetId { get; set; }
        public string assetCode { get; set; }
        public int assetCategoryId { get; set; }
        public int assetTypeId { get; set; }
        public int branchId { get; set; }
        public int? ccenterId { get; set; }
        public string description { get; set; }
        public double cost { get; set; }
        public double? vat { get; set; }
        public double? vatRec { get; set; }
        public double? nbt { get; set; }
        public double bookValue { get; set; }
        public string CreatedBy { get; set; }
        public DateTime CreatedOn { get; set; }
        public DateTime? ModifiedOn { get; set; }
        public string ModifiedBy { get; set; }
        public int Status { get; set; }

        public InvoiceEntities Invoice { get; set; }
        public List<Step2> ListAssets { get; set; }
        public List<tbl_assetcategory> ListCategories { get; set; }
        public List<tbl_branch> ListBranches { get; set; }
        public List<tbl_costcenter> ListDepartments { get; set; }
    }
}

Это мой контроллер:

namespace CapeXPro.Controllers
    {
        [SessionExpire]
        public class FAWizardController : Controller
        {
            UnitOfWork _unitOfWork = new UnitOfWork();
            readonly CommonUtilities _commonService = new CommonUtilities();

            #region Main View
            FAInfo FAInfoComponent(FAInfo model = null)
            {
                try
                {
                    //var existjournaldepreciation = _unitOfWork.JournalDepreciationRepository.GetAll(x => x.Id == 1 && x.Status != (int)StatusEnum.Delete).FirstOrDefault();
                    if (model == null)
                    {
                        model = new FAInfo()
                        {
                            Status = (int)StatusEnum.Active,
                        };
                    }
                    return model;
                }
                catch (Exception ex)
                {
                    throw ex;
                }
            }

            // GET: FAWizard
            public ActionResult FAWizard()
            {
                return View("FAWizard", FAInfoComponent());
            }
            #endregion

            #region Add Or Edit Step2
            [ValidateAntiForgeryToken]
            [HttpPost]
            public ActionResult Step2(FAInfo AssetData, string BtnPrevious, string BtnNext)
            {
                try
                {
                    var action = string.Empty;
                    var before = string.Empty;
                    var after = string.Empty;

                    AssetData = FAInfoComponent(AssetData);

                    if (BtnPrevious != null)
                    {
                        FAInfo InvObj = new FAInfo();

                        InvObj.Step1.InvoiceId = AssetData.Step2.Invoice.InvoiceId;
                        InvObj.Step1.InvoiceNo = AssetData.Step2.Invoice.InvoiceNo;
                        InvObj.Step1.PoNo = AssetData.Step2.Invoice.PoNo;

                        return PartialView("_AddInvoice", InvObj);
                    }
                    if (BtnNext != null)
                    {
                        if (ModelState.IsValid)
                        {
                            var existObj = _unitOfWork.AssetRepository.GetAll(x => x.assetId == AssetData.Step2.assetId && x.Status != (int)StatusEnum.Delete).FirstOrDefault();

                            if (existObj == null)
                            {
                                tbl_asset asset = new tbl_asset()
                                {
                                    assetId = AssetData.Step2.assetId,
                                    assetCode = AssetData.Step2.assetCode,
                                    assetCategoryId = AssetData.Step2.assetCategoryId,

                                    CreatedBy = System.Web.HttpContext.Current.Session[SessionsEnum.UserId.ToString()].ToString(),
                                    CreatedOn = DateTime.Now,
                                    Status = Convert.ToInt32(AssetData.Status)
                                };

                                _unitOfWork.AssetRepository.Insert(asset);
                                //_unitOfWork.Save();
                                //int id = department.CcId;

                                action = ActionType.Insert;
                                before = null;
                                after = asset.assetId + "," +
                                        asset.assetCode + "," +
                                        asset.assetCategoryId + "," +

                                        asset.Status + "," +
                                        asset.CreatedBy + "," +
                                        asset.CreatedOn + "," +
                                        asset.ModifiedBy + "," +
                                        asset.ModifiedOn;
                            }
                            else
                            {
                                FAInfo AssetObj = new FAInfo();

                                AssetObj.Step2.assetId = AssetData.Step2.assetId;
                                AssetObj.Step2.assetCode = AssetData.Step2.assetCode;
                                AssetObj.Step2.assetCategoryId = AssetData.Step2.assetCategoryId;

                                AssetObj.Step2.ModifiedBy = System.Web.HttpContext.Current.Session[SessionsEnum.UserId.ToString()].ToString();
                                AssetObj.Step2.ModifiedOn = DateTime.Now;
                                AssetObj.Step2.Status = Convert.ToInt32(AssetData.Status);

                                _unitOfWork.AssetRepository.Update(existObj);

                                action = ActionType.Update;
                                before = null;
                                after = existObj.assetId + "," +
                                        existObj.assetCode + "," +
                                        existObj.assetCategoryId + "," +

                                        existObj.Status + "," +
                                        existObj.CreatedBy + "," +
                                        existObj.CreatedOn + "," +
                                        existObj.ModifiedBy + "," +
                                        existObj.ModifiedOn;
                            }

                            if (_unitOfWork.Save() > 0)
                            {
                                //Update Log Table
                                AuditLog.SystemLog(Tables.AssetTable, action, before, after);

                                TempData["message"] = Messages.Success;
                                ModelState.Clear();
                                return View("AddDepreciation", new FADepreciationEntities());
                            }
                            else
                            {
                                TempData["message"] = Messages.Failed;
                                return PartialView("_AddAsset", AssetData);
                            }
                        }
                        return PartialView("_AddAsset", AssetData);
                    }
                    return View();
                }
                catch (Exception ex)
                {
                    TempData["message"] = Messages.Exception + ex.Message;
                    return PartialView("_AddAsset", AssetData);
                }
            }
            #endregion

        }
    }

Это мой частичный просмотр

@model DAL.Entities.FAInfo
@using DAL.Enums

@using (Html.BeginForm("Step2", "FAWizard", FormMethod.Post, new { @class = "form-horizontal form-label-left", role = "form", enctype = "multipart/form-data" }))
{
    @Html.AntiForgeryToken()
    @Html.ValidationSummary(true, "", new { @class = "text-danger" })
    @Html.HiddenFor(m => m.Step2.assetId)
    <!-- Editable table -->
    <div class="card">
        <div class="card-body">
            <div id="table" class="table-editable">
                <span class="table-add float-right mb-3 mr-2">
                    <a href="#!" class="text-success">
                        <i class="fas fa-plus fa-2x" aria-hidden="true"></i>
                    </a>
                </span>
                <table id=""
                       class="table table-striped table-hover table-sm table-bordered text-center">
                    <thead>
                        <tr>
                            <th class="text-center">Line No</th>
                            <th class="text-center">Asset Code</th>
                            <th class="text-center">Asset Class</th>
                        </tr>
                    </thead>
                    <tbody>
                        @foreach (DAL.Entities.FAInfo asset in Model)
                        {
                            <tr>
                                <td>1</td>
                                <td>@asset.Step2.assetCode</td>
                                <td>@asset.Step2.ListCategories</td>
                                <td>
                                    <span class="table-remove">
                                        <button type="button"
                                                class="btn btn-danger btn-rounded btn-sm my-0">
                                            Remove
                                        </button>
                                    </span>
                                </td>
                            </tr>
                        }

                    </tbody>
                </table>
            </div>
        </div>
    </div>
}

Это мой MasterView:

@model DAL.Entities.FAInfo
@using DAL.Enums
@{
    ViewBag.Title = "FAWizard";
}

<div class="right_col" role="main">
    <div class="full-height">
        <div class="clearfix"></div>
        <div class="row">
            <div class="col-md-12 col-sm-12 col-xs-12">
                <div class="x_panel">
                    <div class="x_title">
                        <h2>Fixed Assets Capitalization <small>CapeXPro</small></h2>
                        <div class="clearfix"></div>
                    </div>
                    <div class="x_content">
                        <form class="form-horizontal form-label-left" novalidate>
                            <p>
                                For Fixed asset registration - CapeXPro | Union Bank of Colombo
                            </p>
                            <span class="section">Fixed Asset Info</span>
                            <!-- Smart Wizard -->
                            <p>Proceed with the given steps</p>
                            <div id="wizard" class="form_wizard wizard_horizontal">
                                <ul class="wizard_steps">
                                    <li>
                                        <a href="#step-1">
                                            <span class="step_no">1</span>
                                            <span class="step_descr">
                                                Step 1<br />
                                                <small>Invoice and Insurance Details</small>
                                            </span>
                                        </a>
                                    </li>
                                    <li>
                                        <a href="#step-2">
                                            <span class="step_no">2</span>
                                            <span class="step_descr">
                                                Step 2<br />
                                                <small>Asset Details</small>
                                            </span>
                                        </a>
                                    </li>   
                                </ul>
                                <div id="step-1">
                                    @{Html.RenderPartial("_AddInvoice", Model);}
                                </div>
                                <div id="step-2">
                                    @{Html.RenderPartial("_AddAsset", Model);}
                                </div>
                            </div>
                            <!-- End SmartWizard Content -->
                        </form>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
...