Ejemplo n.º 1
0
        // GET: PdSection/Edit/5
        public async Task <ActionResult> Edit(int id)
        {
            PdSection pdSection = await _mediator.Send(new GetPdSectionByIdQuery(id));

            var model = new EditPdSectionModel
            {
                Id                  = pdSection.Id,
                Name                = pdSection.Name,
                Price               = pdSection.Price,
                EmployeeId          = pdSection.EmployeeId,
                OneTimeEmployeeName = pdSection.OneTimeEmployeeName,
                UseOneTimeEmployee  = !string.IsNullOrWhiteSpace(pdSection.OneTimeEmployeeName),
                Employees           = (await _mediator.Send(new ListEmployeesQuery())).Select(item => new SelectListItem
                {
                    Text  = item.FullName,
                    Value = item.Id.ToString()
                }),
                BuildingObjects = (await _mediator.Send(new ListBuildingObjectsQuery())).Select(item => new SelectListItem
                {
                    Value    = item.Id.ToString(),
                    Text     = item.Name,
                    Selected = item.Id == pdSection.BuildingObjectId
                }),
                BuildingObjectId         = pdSection.BuildingObjectId,
                SelectedBuildingObjectId = pdSection.BuildingObjectId
            };

            return(View(model));
        }
        protected override async Task Handle(DetetePdSectionCommand request, CancellationToken cancellationToken)
        {
            var itemToDelete = new PdSection()
            {
                Id = request.Id
            };

            _context.Entry(itemToDelete).State = EntityState.Deleted;
            await _context.SaveChangesAsync(cancellationToken);
        }
Ejemplo n.º 3
0
        public async Task <ActionResult> Delete(int id)
        {
            PdSectionModel model     = null;
            PdSection      pdSection = await _mediator.Send(new GetPdSectionByIdQuery(id)
            {
                IncludeEmployee = true
            });

            if (pdSection != null)
            {
                model = new PdSectionModel
                {
                    Name         = pdSection.Name,
                    Id           = pdSection.Id,
                    Price        = pdSection.Price,
                    EmployeeName = pdSection.OneTimeEmployeeName ?? pdSection.Employee.FullName
                };
            }

            return(View(model));
        }