예제 #1
0
        public async Task <IActionResult> Put(Guid id, [FromBody] DepartmentDTO value)
        {
            var cmd    = new UpdateDepartmentCommand(id, value);
            var result = await _mediator.Send(cmd);

            return(Ok(result));
        }
예제 #2
0
        public void Handle(UpdateDepartmentCommand message)
        {
            if (!message.IsValid())
            {
                NotifyValidationErrors(message);
                return;
            }

            var department         = Department.Create(message.Id, message.DepartmentGroup, message.DepartmentType, message.Description, message.ApplyTax, message.Amount, message.Percentage);
            var existingDepartment = _departmentRepository.GetByDescription(department.Description);

            if (existingDepartment != null)
            {
                if (!existingDepartment.Equals(department))
                {
                    Bus.RaiseEvent(new DomainNotification(message.MessageType, "The Department description has already been taken."));
                    return;
                }
            }

            _departmentRepository.Update(department);

            if (Commit())
            {
                Bus.RaiseEvent(new DepartmentUpdatedEvent(department.DepartmentGroup, department.DepartmentType, department.Description, department.ApplyTax, department.Amount, department.Percentage));
            }
        }
예제 #3
0
    public async Task UpdateDepartmentAsync(UpdateDepartmentCommand command)
    {
        var department = await _departmentRepository.GetDepartmentAsync(command.Id);

        department.UpdateName(command.Name);
        _departmentRepository.Update(department);
        await _unitOfWork.CommitAsync();
    }
예제 #4
0
        public async Task <ActionResult> Edit(UpdateDepartmentCommand command)
        {
            if (await Mediator.Send(command) == null)
            {
                return(BadRequest());
            }

            return(Ok());
        }
예제 #5
0
        public async Task <ActionResult> Update(int id, UpdateDepartmentCommand command)
        {
            if (id != command.Id)
            {
                return(BadRequest());
            }

            await Mediator.Send(command);

            return(NoContent());
        }
예제 #6
0
        public async Task <IActionResult> UpdateDepartment(UpdateDepartmentCommand updateDepartment)
        {
            var result = await Mediator.Send(updateDepartment);

            if (result.Success == false)
            {
                return(result.ApiResult);
            }

            return(NoContent());
        }
예제 #7
0
    public override async Task <Empty> UpdateDepartment(UpdateDepartmentRequest request, ServerCallContext context)
    {
        var command = new UpdateDepartmentCommand
        {
            Id        = request.Id,
            Name      = request.Name,
            IsEnabled = request.IsEnabled,
        };
        await _organizationApp.UpdateDepartmentAsync(command);

        return(new Empty());
    }
예제 #8
0
        public IEnumerable<IEvent> Handle(UpdateDepartmentCommand cmd)
        {
            if (cmd == null)
                throw new ArgumentNullException(nameof(cmd));

            if (cmd.AggregateId == Guid.Empty)
                throw new ArgumentException(nameof(cmd.AggregateId));

            if (string.IsNullOrEmpty(nameof(cmd.Name)))
                throw new ArgumentException(nameof(cmd.AggregateId));

            var events = new List<IEvent>();
            events.Add(new UpdateDepartmentEvent(cmd.AggregateId, cmd.Name));
            return events;
        }
예제 #9
0
        public async Task <ActionResult> UpdateDepartmentAsync(UpdateDepartmentCommand updateDepartmentCommand)
        {
            bool commandResult = false;

            _logger.LogInformation(
                "----- Sending command: {CommandName} - {IdProperty}: {CommandId} ({@Command})",
                updateDepartmentCommand.GetType().Name,
                nameof(updateDepartmentCommand.Id),
                updateDepartmentCommand.Id,
                updateDepartmentCommand);

            commandResult = await _mediator.Send(updateDepartmentCommand);

            if (!commandResult)
            {
                return(BadRequest());
            }

            return(Ok());
        }
예제 #10
0
        public IEnumerable <IEvent> Handle(UpdateDepartmentCommand cmd)
        {
            if (cmd == null)
            {
                throw new ArgumentNullException(nameof(cmd));
            }

            if (cmd.AggregateId == Guid.Empty)
            {
                throw new ArgumentException(nameof(cmd.AggregateId));
            }

            if (string.IsNullOrEmpty(nameof(cmd.Name)))
            {
                throw new ArgumentException(nameof(cmd.AggregateId));
            }

            var events = new List <IEvent>();

            events.Add(new UpdateDepartmentEvent(cmd.AggregateId, cmd.Name));
            return(events);
        }
예제 #11
0
        public async Task <IActionResult> UpdateDepartment([FromBody] UpdateDepartmentCommand department)
        {
            var command = await _mediator.Send(department);

            return(Ok(command));
        }
예제 #12
0
 public async Task <IActionResult> UpdateDepartment([FromBody] UpdateDepartmentCommand command)
 {
     return(Ok(await Mediator.Send(command)));
 }
        public async Task <IActionResult> Update([FromBody] UpdateDepartmentCommand command)
        {
            await Mediator.Send(command);

            return(NoContent());
        }
예제 #14
0
 public static Department ToDepartment(this UpdateDepartmentCommand command)
 {
     return(command.MapTo <UpdateDepartmentCommand, Department>());
 }
예제 #15
0
        public async Task <IActionResult> Edit(UpdateDepartmentCommand command)
        {
            try
            {
                await Mediator.Send(command);

                return(RedirectToAction(nameof(Index)));
            }
            catch (DbUpdateConcurrencyException ex)
            {
                var vm = new UpdateDepartmentVM
                {
                    DepartmentID = command.DepartmentID.Value,
                    Name         = command.Name,
                    Budget       = command.Budget,
                    StartDate    = command.StartDate,
                    InstructorID = command.InstructorID,
                    RowVersion   = command.RowVersion
                };

                var exceptionEntry = ex.Entries.Single();
                var clientValues   = (Department)exceptionEntry.Entity;
                var databaseEntry  = exceptionEntry.GetDatabaseValues();
                if (databaseEntry == null)
                {
                    ModelState.AddModelError(string.Empty,
                                             "Unable to save changes. The department was deleted by another user.");
                }
                else
                {
                    var databaseValues = (Department)databaseEntry.ToObject();

                    if (databaseValues.Name != clientValues.Name)
                    {
                        ModelState.AddModelError("Name", $"Current value: {databaseValues.Name}");
                    }
                    if (databaseValues.Budget != clientValues.Budget)
                    {
                        ModelState.AddModelError("Budget", $"Current value: {databaseValues.Budget:c}");
                    }
                    if (databaseValues.StartDate != clientValues.StartDate)
                    {
                        ModelState.AddModelError("StartDate", $"Current value: {databaseValues.StartDate:d}");
                    }
                    if (databaseValues.InstructorID != clientValues.InstructorID)
                    {
                        //Models.Instructor databaseInstructor = await _context.Instructors.FirstOrDefaultAsync(i => i.ID == databaseValues.InstructorID);
                        //ModelState.AddModelError("InstructorID", $"Current value: {databaseInstructor?.FullName}");
                    }

                    ModelState.AddModelError(string.Empty, "The record you attempted to edit "
                                             + "was modified by another user after you got the original value. The "
                                             + "edit operation was canceled and the current values in the database "
                                             + "have been displayed. If you still want to edit this record, click "
                                             + "the Save button again. Otherwise click the Back to List hyperlink.");
                    vm.RowVersion = (byte[])databaseValues.RowVersion;
                    ModelState.Remove("RowVersion");
                }

                var instructorsLookup = await Mediator.Send(new GetInstructorLookupCommand());

                ViewData["InstructorID"] = new SelectList(instructorsLookup, "ID", "FullName", command.InstructorID);

                return(View(vm));
            }

            ////-----------------------------
            //if (id == null)
            //{
            //    return NotFound();
            //}

            //var departmentToUpdate = await _context.Departments.Include(i => i.Administrator).FirstOrDefaultAsync(m => m.DepartmentID == id);

            //if (departmentToUpdate == null)
            //{
            //    Models.Department deletedDepartment = new Models.Department();
            //    await TryUpdateModelAsync(deletedDepartment);
            //    ModelState.AddModelError(string.Empty,
            //        "Unable to save changes. The department was deleted by another user.");

            //    var instructorsList = await Mediator.Send(new GetInstructorLookupCommand());
            //    ViewData["InstructorID"] = new SelectList(instructorsList, "ID", "FullName", deletedDepartment.InstructorID);
            //    return View(deletedDepartment);
            //}

            //_context.Entry(departmentToUpdate).Property("RowVersion").OriginalValue = rowVersion;

            //if (await TryUpdateModelAsync<Models.Department>(
            //    departmentToUpdate,
            //    "",
            //    s => s.Name, s => s.StartDate, s => s.Budget, s => s.InstructorID))
            //{
            //    try
            //    {
            //        await _context.SaveChangesAsync();
            //        return RedirectToAction(nameof(Index));
            //    }
            //    catch (DbUpdateConcurrencyException ex)
            //    {
            //        var exceptionEntry = ex.Entries.Single();
            //        var clientValues = (Models.Department)exceptionEntry.Entity;
            //        var databaseEntry = exceptionEntry.GetDatabaseValues();
            //        if (databaseEntry == null)
            //        {
            //            ModelState.AddModelError(string.Empty,
            //                "Unable to save changes. The department was deleted by another user.");
            //        }
            //        else
            //        {
            //            var databaseValues = (Models.Department)databaseEntry.ToObject();

            //            if (databaseValues.Name != clientValues.Name)
            //            {
            //                ModelState.AddModelError("Name", $"Current value: {databaseValues.Name}");
            //            }
            //            if (databaseValues.Budget != clientValues.Budget)
            //            {
            //                ModelState.AddModelError("Budget", $"Current value: {databaseValues.Budget:c}");
            //            }
            //            if (databaseValues.StartDate != clientValues.StartDate)
            //            {
            //                ModelState.AddModelError("StartDate", $"Current value: {databaseValues.StartDate:d}");
            //            }
            //            if (databaseValues.InstructorID != clientValues.InstructorID)
            //            {
            //                Models.Instructor databaseInstructor = await _context.Instructors.FirstOrDefaultAsync(i => i.ID == databaseValues.InstructorID);
            //                ModelState.AddModelError("InstructorID", $"Current value: {databaseInstructor?.FullName}");
            //            }

            //            ModelState.AddModelError(string.Empty, "The record you attempted to edit "
            //                    + "was modified by another user after you got the original value. The "
            //                    + "edit operation was canceled and the current values in the database "
            //                    + "have been displayed. If you still want to edit this record, click "
            //                    + "the Save button again. Otherwise click the Back to List hyperlink.");
            //            departmentToUpdate.RowVersion = (byte[])databaseValues.RowVersion;
            //            ModelState.Remove("RowVersion");
            //        }
            //    }
            //}

            //var instructors = await Mediator.Send(new GetInstructorLookupCommand());
            //ViewData["InstructorID"] = new SelectList(instructors, "ID", "FullName", departmentToUpdate.InstructorID);
            //return View(departmentToUpdate);
        }
예제 #16
0
 public async Task <IActionResult> Edit(UpdateDepartmentCommand command) => Json(await Mediator.Send(command));