Monday, 23 May 2016

How to more than one list value to add another list value in MVC?

 *************Employee Model*******************
 public classEmployeeModel
    {
        public EmployeeModel()
        {
            EmployeeList = new List<EmployeeModel>();
            StudentList = new List<EmployeeModel>();

            ServiceList = new List<SelectListItem>();
            ParentList = new List<SelectListItem>();
            GenderList= new List<SelectListItem>
            {
               new SelectListItem() {Text = "--Select--", Value ="0" },
               new SelectListItem() {Text = "Male", Value ="1" },
               new SelectListItem() {Text = "Female", Value ="2"},
             };
        }
        public int ID { get; set; }
        public string Name{ get; set; }
        public string Address{ get; set; }
        public int Age{ get; set; }
        public string Mobile{ get; set; }
     
        public List<EmployeeModel> EmployeeList { get; set; }
        public List<EmployeeModel> StudentList { get; set; }
        public IEnumerable<Employee> SerList { get; set; }

        public decimal? ServiceUsage { get; set; }
        public decimal? ServiceCost_Per_Annum { get; set; }
        public decimal? ServiceCost_for_Service { get; set; }

        public List<SelectListItem> GenderList{ get; set; }

    }

************************End Employee Model**************************
var empList = _apiService.GetAllEmployee().ToList();
                    model.EmployeeList = stcList.Select(x =>
                    {
                        return new EmployeeModel()
                        {
                            ID = x.ID == null ? 0 : x.ID.Value,
                            Name = string.IsNullOrEmpty(x.Name) ? "" : x.Name,
                            Address= string.IsNullOrEmpty(x.Address) ? "" : x.Address,
                            Mobile= string.IsNullOrEmpty(x.Mobile) ? "" : x.Mobile,
                            Age= x.Age == null ? Convert.ToInt32(0) : x.Age,
                        };
                    }).ToList();

                    var stuList = _apiService.GetAllStudent().ToList();
                    model.StudentList = stuList .Select(x =>
                        {
                            return new ComponentModel()
                            {
                               ID = x.ID == null ? 0 : x.ID.Value,
                            Name = string.IsNullOrEmpty(x.Name) ? "" : x.Name,
                            Address= string.IsNullOrEmpty(x.Address) ? "" : x.Address,
                            Mobile= string.IsNullOrEmpty(x.Mobile) ? "" : x.Mobile,
                            Age= x.Age == null ? Convert.ToInt32(0) : x.Age,
                            };
                        }).ToList();


var AddExData = new List<EmployeeModel>();

AddExData.AddRange(model.EmployeeList);
AddExData.AddRange(model.StudentList);

No comments:

Post a Comment