public static EquipmentAggregate ToModel(this EquipmentCreateViewModel model)
        {
            EquipmentAggregate entity = null;

            if (model != null)
            {
                var    ids   = Regex.Split(model.DepartmentId, @"#\$#").ToList();
                string fId   = ids[0];
                string fName = "";
                if (ids.Count() > 1)
                {
                    fName = ids[1];
                }
                entity = new EquipmentAggregate()
                {
                    Id             = Guid.NewGuid(),
                    Name           = model.Name,
                    Model          = model.EquipmentModel,
                    DepartmentId   = new  Guid(fId),
                    DepartmentName = fName.Replace("#+#", " "),
                    Description    = model.Description,
                };
            }

            return(entity);
        }
Example #2
0
        public async Task LoadAsync() //method must be async when loading in async data and return a task
        {
            //load list data
            await EquipmentListViewModel.LoadAsync();

            await ComponentListViewModel.LoadAsync();

            await CustomerListViewModel.LoadAsync();

            await CustomerCreateViewModel.LoadEquipment();

            await AddRemoveEquipmentToFromCustomerViewModel.LoadAsync();

            await AddRemoveEquipmentToFromCustomerViewModel.LoadEquipmentAsync();

            await EquipmentCreateViewModel.LoadTypesAsync();

            await EquipmentCreateViewModel.LoadConfigurationsAsync();

            await EquipmentCreateViewModel.LoadCategoriesAsync();

            await EquipmentDetailViewModel.LoadTypesAsync();

            await EquipmentDetailViewModel.LoadConfigurationsAsync();

            await EquipmentDetailViewModel.LoadCategoriesAsync();
        }
        public async Task <ActionResult> Create(EquipmentCreateViewModel model)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    var equip = model.ToModel();
                    await this._equipmentAggregateManagementService.AddEquipmentAsync(equip);

                    return(RedirectToAction("Index"));
                }

                return(View(model));
                // TODO: Add insert logic here
            }
            catch
            {
                return(View(model));
            }
        }
        // GET: Equipment/Create
        public async Task <ActionResult> Create()
        {
            try
            {
                EquipmentCreateViewModel model = new EquipmentCreateViewModel();
                var fmodel = await _departmentAggregateManagementService.GetAllDepartmentsAsync();

                if (fmodel != null)
                {
                    model.FacilitiesModel = fmodel.Select(x => new SelectListItem()
                    {
                        Value = x.Id.ToString() + "#$#" + x.Name.Replace(" ", "#+#"),
                        Text  = x.Name
                    });
                }

                return(View(model));
            }
            catch
            {
                return(View());
            }
        }