using Nop.Admin.Validators.Equipment;
using Nop.Core.Domain.Catalog;
using Nop.Core.Domain.Equipment;
using Nop.Core.Domain.Models;
using Nop.Web.Framework;
using Nop.Web.Framework.Mvc;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using FluentValidation.Attributes;
namespace Nop.Admin.Models.Equipment
{
[Validator(typeof(EquipmentValidator))]
public partial class EquipmentModel : BaseNopEntityModel
{
public EquipmentModel()
{
AvailableManufacturers = new List<SelectListItem>();
AvailableModel = new List<SelectListItem>();
AvailableModelType = new List<SelectListItem>();
AvailableStatus = new List<SelectListItem>();
AvailableFilterMaintenance = new List<SelectListItem>();
EquipmentFilterMaintenanceDtls = new List<EquipmentFilterMaintenance>();
EquipmentPictureModels = new List<EquipmentPictureModel>();
AvailableVendors = new List<SelectListItem>();
AddPictureModel = new EquipmentPictureModel();
AvailableEquipments = new List<SelectListItem>();
AvailableEquipmentRentalFrequencies =new List<SelectListItem>();
}
[Key, DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public override int Id { get; set; }
[NopResourceDisplayName("Admin.Equipment.Fields.EquipmentName")]
public string Name { get; set; }
[NopResourceDisplayName("Admin.Equipment.Fields.EquipmentID")]
public string AssetID { get; set; }
[NopResourceDisplayName("Admin.Equipment.Fields.SerialNo")]
public string SerialNo { get; set; }
[NopResourceDisplayName("Admin.Equipment.Fields.ManufacturerID")]
public int ManufacturerID { get; set; }
public IList<SelectListItem> AvailableManufacturers { get; set; }
[NopResourceDisplayName("Admin.Equipment.Fields.ModelID")]
public int ModelID { get; set; }
public IList<SelectListItem> AvailableModel { get; set; }
[NopResourceDisplayName("Admin.Equipment.Fields.ModelTypeID")]
public int ModelTypeID { get; set; }
public IList<SelectListItem> AvailableModelType { get; set; }
[NopResourceDisplayName("Admin.Equipment.Fields.Description")]
public string Description { get; set; }
[NopResourceDisplayName("Admin.Equipment.Fields.FilterMaintenanceID")]
[NotMapped]
public int FilterMaintenanceID { get; set; }
[NotMapped]
public string PictureThumbnailUrl { get; set; }
public IList<SelectListItem> AvailableFilterMaintenance { get; set; }
public List<EquipmentFilterMaintenance> EquipmentFilterMaintenanceDtls { get; set; }
[NopResourceDisplayName("Admin.Equipment.Fields.SellPrice")]
public decimal CostPrice { get; set; }
[NopResourceDisplayName("Admin.Equipment.Fields.WarrantyPeriod")]
public int WarrantyPeriod { get; set; }
public int WarrantyUnit { get; set; }
[NopResourceDisplayName("Admin.Equipment.Fields.StatusID")]
public int StatusID { get; set; }
public IList<SelectListItem> AvailableStatus { get; set; }
[NopResourceDisplayName("Admin.Equipment.Fields.PurchasedDate")]
public DateTime? PurchasedDate { get; set; }
[NopResourceDisplayName("Admin.Equipment.Fields.RetiredDate")]
public DateTime? RetiredDate { get; set; }
[NopResourceDisplayName("Admin.Equipment.Fields.Color")]
public string Color { get; set; }
public int? CreatedBy { get; set; }
public DateTime? CreatedOnUtc { get; set; }
public int? UpdatedBy { get; set; }
public DateTime? UpdatedOnUtc { get; set; }
public bool IsDeleted { get; set; }
public Manufacturer Manufacturer { get; set; }
public Nop.Admin.Models.EquipmentModel.ModelModel Model { get; set; }
public ModelType ModelType { get; set; }
public Status Status { get; set; }
[NopResourceDisplayName("Admin.Equipment.Fields.isAutomatic")]
public bool isAutomatic { get; set; }
[NopResourceDisplayName("Admin.Equipment.Fields.isPourOver")]
public bool isPourOver { get; set; }
[NopResourceDisplayName("Admin.Equipment.Fields.isVendor")]
public bool isVendor { get; set; }
[NopResourceDisplayName("Admin.Equipment.Fields.vendorId")]
public int vendorId { get; set; }
public bool? IsEquipmentSold { get; set; }
public IList<SelectListItem> AvailableVendors { get; set; }
public IList<EquipmentPictureModel> EquipmentPictureModels { get; set; }
public EquipmentPictureModel AddPictureModel { get; set; }
public int EquipmentId { get; set; }
public IList<SelectListItem> AvailableEquipments { get; set; }
public EquipmentShortSummaryModel EquipmentShortSummary { get; set; }
//[Validator(typeof(EquipmentValidator))]
public partial class EquipmentPictureModel : BaseNopEntityModel
{
public int EquipmentId { get; set; }
[UIHint("Picture")]
[NopResourceDisplayName("Admin.Catalog.Equipment.Pictures.Fields.PicturePreview")]
public int PictureId { get; set; }
[NopResourceDisplayName("Admin.Catalog.Equipment.Pictures.Fields.PictureUrl")]
public string PictureUrl { get; set; }
[Required(ErrorMessage = "Display order is required.")]
[NopResourceDisplayName("Admin.Catalog.Equipment.Pictures.Fields.DisplayOrder")]
public int DisplayOrder { get; set; }
[NopResourceDisplayName("Admin.Catalog.Equipment.Pictures.Fields.IsDefault")]
public Boolean? IsDefault { get; set; }
public Boolean IsModelPic { get; set; } // if the picture came from model the equipment belongs to then this column value will be true. So that the image cannot be deleted
[Required(ErrorMessage = "Title is required.")]
[NopResourceDisplayName("Admin.Catalog.Equipment.Pictures.Fields.Title")]
public string Title { get; set; }
[Required(ErrorMessage = "Alternate Text is required.")]
[NopResourceDisplayName("Admin.Catalog.Equipment.Pictures.Fields.AlternateText")]
public string AlternateText { get; set; }
}
[NopResourceDisplayName("Admin.Equipment.Fields.StandardRentalCharge")]
public decimal StandardRentalCharge { get; set; }
[NopResourceDisplayName("Admin.Equipment.Fields.EquipmentRentalFrequencyId")]
public int EquipmentRentalFrequencyID { get; set; }
public IList<SelectListItem> AvailableEquipmentRentalFrequencies { get; set; }
public EquipmentRentalFrequency EquipmentRentalFrequency { get; set; }
[NopResourceDisplayName("Admin.Equipment.Fields.IsTaxable")]
public bool IsTaxable { get; set; }
}
}
MVC CONROLLER
public partial class HomeController : Controller
//GET
{
public JsonResult GetEquipmentWebAPI(string assetNo)
{
var result = GetEquipment(assetNo);
var serializer = new JavaScriptSerializer();
if (result.Data != null)
{
//return Json(result, JsonRequestBehavior.AllowGet);
return Json(serializer.Serialize(result), JsonRequestBehavior.AllowGet);
}
else
{
return Json(new { Id = 0, Value = "Not Available" }, JsonRequestBehavior.AllowGet);
}
}
//Post
public JsonResult CreateEquipmentWebAPI(EquipmentModel model)
{
var serializer = new JavaScriptSerializer();
model.CreatedOnUtc = DateTime.Now;
model.CreatedBy = EngineContext.Current.Resolve<IWorkContext>().CurrentCustomer.Id;
model.UpdatedOnUtc = DateTime.Now;
EquipmentFilterMaintenance obj = new EquipmentFilterMaintenance();
obj.FilterMaintenanceID = model.FilterMaintenanceID;
model.EquipmentFilterMaintenanceDtls.Add(obj);
var entity = model.ToEntity();
int id = _equipmentService.InsertEquipment(entity);
TempData["EquipmentAdded"] = id.ToString() + "," + model.AssetID + "," + _modelService.GetModelById(model.ModelID).Name + "," + model.SerialNo;
TempData["IsFromBarcodeScanning"] = true;
TempData["IsNewEquipment"] = true;
return Json(serializer.Serialize(model.AssetID + ", is Created"), JsonRequestBehavior.AllowGet);
}
}
Web api controller
public class HomeController : ApiController
{
public JsonResult CheckForExistingEquipment(string assetNo)
{
var barcodeController = DependencyResolver.Current.GetService<Nop.Admin.Controllers.BarcodeController>();
var result = barcodeController.GetEquipmentWebAPI(assetNo);
var serializer = new JavaScriptSerializer();
return result;
}
public JsonResult CreateEquipmentWebAPI(EquipmentModel model)
{
var barcodeController = DependencyResolver.Current.GetService<Nop.Admin.Controllers.BarcodeController>();
var result = barcodeController.CreateEquipmentWebAPI(model);
return result;
}
}
No comments:
Post a Comment