Exemplo n.º 1
0
        private void InitItems()
        {
            Items.Add(new ActionItem("Add Electrical System", () =>
            {
                var settings = new Dictionary <string, object>
                {
                    { "ResizeMode", ResizeMode.NoResize },
                    { "WindowStartupLocation", WindowStartupLocation.CenterScreen }
                };

                var facility           = CreateNewElectricalSystem();
                var eventAggreggor     = IoC.Get <IEventAggregator>();
                var windowManager      = IoC.Get <IInvWindowManager>();
                var facilityService    = IoC.Get <IFacilitiesService>();
                var applicationContext = IoC.Get <IApplicationContext>();
                var facilityInfoVm     = new FacilityInfoViewModel(facility, applicationContext, eventAggreggor);
                var facilityVM         = new FacilityDetailViewModel(facility, facilityInfoVm, windowManager, eventAggreggor, applicationContext, facilityService);
                var vm = new FacilityCreateViewModel(facilityVM, eventAggreggor, windowManager);
                windowManager.ShowDialog(vm, null, settings);
            }));

            Items.Add(new ActionItem("Add Mechanical System", null));
            Items.Add(new ActionItem("Add Electrical Equipment", null));
            Items.Add(new ActionItem("Add Electrical Equipment", null));
        }
        public async Task <ActionResult> Create(FacilityCreateViewModel model)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    var org = model.ToModel();
                    await _organizationManagementService.AddAsync(org);

                    return(RedirectToAction("Index"));
                }

                return(View(model));
                // TODO: Add insert logic here
            }
            catch
            {
                return(View(model));
            }
        }
        public static Organization ToModel(this FacilityCreateViewModel model)
        {
            Organization entity = null;

            if (model != null)
            {
                entity = new Organization()
                {
                    Id      = Guid.NewGuid(),
                    Name    = model.Name,
                    Address = new Address()
                    {
                        Id           = Guid.NewGuid(),
                        AddressLine1 = model.Address,
                        City         = model.City,
                        ZipCode      = model.ZipCode
                    }
                };
            }

            return(entity);
        }