Пример #1
0
        public async Task <IActionResult> Post([FromBody] AcquiredKnowledge acquiredKnowledge)
        {
            if (ModelState.IsValid)
            {
                //var newCommitment = Mapper.Map<Commitment>(commitment);
                var addedacquiredKnowledge = _repo.Create(acquiredKnowledge);

                return(Created($"api/dashboard/commitments/{addedacquiredKnowledge.Id}", addedacquiredKnowledge));
            }
            return(BadRequest("Failed to save changes to the database"));
        }
Пример #2
0
        public async Task <IActionResult> Post([FromBody] EmployeePost employee)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    var newEmployee = new Employee
                    {
                        FirstName = employee.FirstName,
                        LastName  = employee.LastName,
                        PersonNr  = employee.PersonNr
                    };

                    var addedEmployee = await _empRepo.Create(newEmployee);


                    if (employee.knowledges == null && employee.newKnowledges != null)
                    {
                        foreach (var newKnowledge in employee.newKnowledges)
                        {
                            var AddedKnowledges = await _KnRepo.Create(new Knowledge
                            {
                                KnowledgeName = newKnowledge
                            });

                            var addedAssignment = await _AcqRepo.Create(new AcquiredKnowledge
                            {
                                EmployeeId  = addedEmployee.EmployeeId,
                                KnowledgeId = AddedKnowledges.KnowledgeId
                            });
                        }
                    }
                    else if (employee.knowledges != null && employee.newKnowledges == null)
                    {
                        foreach (var knowledge in employee.knowledges)
                        {
                            var addedAssignment = await _AcqRepo.Create(new AcquiredKnowledge
                            {
                                EmployeeId  = addedEmployee.EmployeeId,
                                KnowledgeId = knowledge.KnowledgeId
                            });
                        }
                    }
                    else if (employee.knowledges != null && employee.newKnowledges != null)
                    {
                        foreach (var newKnowledge in employee.newKnowledges)
                        {
                            var AddedKnowledges = await _KnRepo.Create(new Knowledge
                            {
                                KnowledgeName = newKnowledge
                            });

                            var addedAssignment = await _AcqRepo.Create(new AcquiredKnowledge
                            {
                                EmployeeId  = addedEmployee.EmployeeId,
                                KnowledgeId = AddedKnowledges.KnowledgeId
                            });
                        }
                        foreach (var knowledge in employee.knowledges)
                        {
                            var addedAssignment = await _AcqRepo.Create(new AcquiredKnowledge
                            {
                                EmployeeId  = addedEmployee.EmployeeId,
                                KnowledgeId = knowledge.KnowledgeId
                            });
                        }
                    }

                    return(Ok(addedEmployee));
                }
                catch (Exception ex)
                {
                    _logger.LogError($"Exception thrown while adding employee: {ex.Message}");
                    return(BadRequest($"Error ocurred"));
                }
            }
            return(BadRequest("Failed to save changes to the database"));
        }