コード例 #1
0
        public async Task <IActionResult> Create([FromBody] SkillCreateDTO skillDTO)
        {
            try
            {
                _logger.LogInfo($"Skill submission attempted.");
                if (skillDTO == null)
                {
                    _logger.LogWarn($"Empty Request was submitted.");
                    return(BadRequest(ModelState));
                }
                if (!ModelState.IsValid)
                {
                    _logger.LogWarn($"Skill Data was Invalid.");
                    return(BadRequest(ModelState));
                }
                var skill     = _mapper.Map <Skill>(skillDTO);
                var isSuccess = await _skillRepository.Create(skill);

                if (!isSuccess)
                {
                    return(InternalError($"Skill creation failed."));
                }
                _logger.LogInfo("Skill created");
                return(Created("Create", new { skill }));
            }
            catch (Exception e)
            {
                return(InternalError($"{e.Message} - {e.InnerException}"));
            }
        }
コード例 #2
0
        public IResult CreateSkill(SkillViewModel skill)
        {
            var result = new Result
            {
                Operation = Operation.Create,
                Status    = Status.Success
            };

            try
            {
                var duplicateSkill = _skillRepository.GetFirstOrDefault(x => x.Name == skill.Name);
                if (duplicateSkill != null)
                {
                    result.Status  = Status.Fail;
                    result.Message = SkillStatusNotification.DuplicateSkill;
                    result.Body    = null;
                }
                else
                {
                    var skillModel = new Skills();
                    skillModel.MapFromViewModel(skill, (ClaimsIdentity)_principal.Identity);
                    _skillRepository.Create(skillModel);
                    _skillRepository.SaveChanges();
                    result.Body = skillModel;
                }
            }
            catch (Exception e)
            {
                result.Message = e.Message;
                result.Status  = Status.Error;
            }
            return(result);
        }
コード例 #3
0
ファイル: SkillsController.cs プロジェクト: xprasoulas/grid
        public ActionResult Update(Skill skill)
        {
            ApiResult <Skill> apiResult;

            if (ModelState.IsValid)
            {
                if (skill.Id > 0)
                {
                    apiResult = TryExecute(() =>
                    {
                        _skillRepository.Update(skill);
                        _unitOfWork.Commit();
                        return(skill);
                    }, "Skill updated sucessfully");
                }
                else
                {
                    apiResult = TryExecute(() =>
                    {
                        _skillRepository.Create(skill);
                        _unitOfWork.Commit();
                        return(skill);
                    }, "Skill created sucessfully");
                }
            }
            else
            {
                apiResult = ApiResultFromModelErrors <Skill>();
            }

            return(Json(apiResult, JsonRequestBehavior.AllowGet));
        }
コード例 #4
0
        public IActionResult CreateSkill([FromBody] Skill skill)
        {
            var lang          = Request.Headers["language"].ToString();
            var errorMessages = new List <string>();

            try
            {
                var category = _skillCategoryRepository.FindById(skill.CategoryId);
                if (category == null)
                {
                    return(NotFound());
                }

                var newSkill = new Skill
                {
                    Category   = category,
                    CategoryId = category.Id,
                    Name_EN    = skill.Name_EN,
                    Name_FR    = !string.IsNullOrEmpty(skill.Name_FR) ? skill.Name_FR : skill.Name_EN,
                    Level      = skill.Level
                };

                var createdSkill = _skillRepository.Create(newSkill);

                return(Ok(new { createdSkill }));
            }
            catch
            {
                errorMessages.Add(_translator.GetTranslation("ERROR", lang));
                return(BadRequest(new { errors = errorMessages }));
            }
        }
コード例 #5
0
        public OperationResult Create(CreateSkill command)
        {
            var operation = new OperationResult();

            var skill = new Skills(command.SkillName, command.SkillPercent, command.Description, command.ShowOrder);

            _skillRepository.Create(skill);
            _skillRepository.SaveChanges();

            return(operation.Succedded());
        }
        public async Task <IActionResult> OnPost()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            await _repository.Create(Skill);

            return(RedirectToPage("Index"));
        }
コード例 #7
0
ファイル: SkillsController.cs プロジェクト: nypen/Scheduler
        public async Task <ActionResult <Skill> > PostSkill(Skill skill)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }

            await _skillRepository.Create(skill);

            return(CreatedAtAction("GetSkill", new { id = skill.ID }, skill));
        }
コード例 #8
0
        public async Task <ActionResult> Create([Bind] Skill skill)
        {
            logger.Info($"Action Start | Controller name: {nameof(SkillsController)} | Action name: {nameof(Create)} | Input params: {nameof(skill.Name)}={skill.Name}, {nameof(skill.Key)}={skill.Key}, {nameof(skill.Algorithm)}={skill.Algorithm}");

            if (ModelState.IsValid)
            {
                repository.Create(skill);
                await repository.SaveAsync();

                return(RedirectToAction("Index"));
            }

            return(View(skill));
        }
コード例 #9
0
        public void CreateSkill()
        {
            var skill = new Skill {
                Development = "Java", Certification = "Ololowa"
            };
            var skill1 = new Skill {
                Development = "Useless", Certification = "Ahahah", Degree = Degree.Competent
            };

            skillRepository.Create(skill);
            skillRepository.Create(skill1);
            contextManager.BatchSave();

            Assert.That(skillRepository.GetSkillById(skill.Id), !Is.Null);
            Assert.That(skill.Id, !Is.NaN);
            Assert.That(skill.Id, Is.Positive);
            Assert.IsInstanceOf(typeof(int), skill.Id);

            Assert.That(skillRepository.GetSkillById(skill1.Id), !Is.Null);
            Assert.That(skill1.Id, !Is.NaN);
            Assert.That(skill1.Id, Is.Positive);
            Assert.IsInstanceOf(typeof(int), skill1.Id);
        }
コード例 #10
0
 public IActionResult SkillCreate(SkillModel model)
 {
     if (ModelState.IsValid)
     {
         var entity = new Skill()
         {
             SkillName = model.SkillName,
             SkillRate = model.SkillRate,
         };
         _skillRepository.Create(entity);
         return(RedirectToAction("SkillList"));
     }
     return(View(model));
 }
        public async Task <ActionResult> CreateNewSkill(Skill skill)
        {
            try
            {
                if (skill == null)
                {
                    return(BadRequest());
                }
                var skillCreated = await _repository.Create(skill);

                return(CreatedAtAction(nameof(GetSkillById), new { id = skillCreated.SkillId }, skillCreated));
            }
            catch (System.Exception)
            {
                return(StatusCode(StatusCodes.Status500InternalServerError,
                                  "There were error in creating new skill, Please contact your admin!"));
            }
        }
コード例 #12
0
ファイル: SkillService.cs プロジェクト: adichourasiya/skill
 /// <summary>
 /// Insert skill into table Skill
 /// </summary>
 /// <param name="skill"></param>
 /// <returns></returns>
 public int Create(SkillDTO skill)
 {
     return(_iSkillRepository.Create(skill.ToModel()));
 }
コード例 #13
0
 public async Task <IActionResult> Post([FromBody] Skill skill)
 {
     skillRepository.Create(skill);
     unitofwork.commit();
     return(Ok(skill));
 }
コード例 #14
0
 public Guid Create(Skill item)
 {
     _repository.Create(Mapping.Mapped.Map <Domain.Entities.Skill>(item));
     return(item.SkillId);
 }
コード例 #15
0
 public void CreateSkill(SkillEntity skill)
 {
     skillRepository.Create(skill.ToDalSkill());
     uow.Commit();
 }