Beispiel #1
0
        public async Task <IActionResult> Create([FromBody] DivisionCreateViewModel input)
        {
            var user     = User.GetDetails();
            var data     = _mapper.Map <DivisionCreateViewModel, Division>(input);
            var division = new Division(input.Name, input.Code, input.Status, user.Id);

            if (await _unitOfWork.Divisions.AnyAsync(division))
            {
                return(BadRequest("Division Already Exists"));
            }
            division.AddSubDivisions(data.SubDivisions.ToList(), user.Id);
            _unitOfWork.Divisions.Add(division);
            await _unitOfWork.CompleteAsync(user.Id);

            return(Ok(division));
        }