public async Task <IHttpActionResult> SaveCourse([FromBody] Course model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }
            db.Courses.Add(model);
            await db.SaveChangesAsync();

            return(Ok(new ResponseMessage <Course>
            {
                Result = model
            }));
        }
예제 #2
0
        public async Task <IHttpActionResult> SaveStudent([FromBody] Student model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            db.Students.Add(model);
            await db.SaveChangesAsync();

            return(Ok(new ResponseMessage <Student>
            {
                Result = model
            }));
        }
        public async Task Consume(ConsumeContext <CreateDepartmentRequest> context)
        {
            var department = new Domain.Department
            {
                DepartmentName = context.Message.Name
            };

            await _dbContext.Departments.AddAsync(department);

            await _dbContext.SaveChangesAsync();

            await context.RespondAsync(new CreateDepartmentResponse
            {
                Name = context.Message.Name,
                Id   = department.Id
            });
        }
예제 #4
0
        public async Task Consume(ConsumeContext <DeleteDepartmentRequest> context)
        {
            var department = _dbContext.Departments.FirstOrDefault(x => x.Id == context.Message.DepartmentId);

            if (department != null && department.EmployeeCount == 0)
            {
                _dbContext.Entry(department).State = EntityState.Deleted;
                await _dbContext.SaveChangesAsync();

                await context.RespondAsync(new DeleteDepartmentResponse
                {
                    DepartmentId = context.Message.DepartmentId,
                    IsDeleted    = true
                });
            }

            await context.RespondAsync(new DeleteDepartmentResponse
            {
                DepartmentId = context.Message.DepartmentId,
                IsDeleted    = false
            });
        }