예제 #1
0
 public static Core.Library.Entities.Program ToProgramEntity(ProgramCreateModel model)
 {
     return(new Core.Library.Entities.Program
     {
         Name = model.ProgramName,
     });
 }
예제 #2
0
        public async Task <IActionResult> Create([Bind("ProgramName")] ProgramCreateModel programCreateModel)
        {
            if (ModelState.IsValid)
            {
                var result = ProgramMappings.ToProgramEntity(programCreateModel);
                var beforeCreatedProgam = _repository.Query <Core.Library.Entities.Program>().FirstOrDefault(x => x.Name == result.Name);
                if (beforeCreatedProgam != null)
                {
                    _logger.LogWarning($"User {_user} tried to create existing program {result.Name}");
                    TempData["ErrorMessage"] = "Ši programa jau yra sukurta";
                    return(RedirectToAction(nameof(Create)));
                }
                await _repository.InsertAsync <Core.Library.Entities.Program>(result);

                _logger.LogInformation($"User {_user} created program {result.Name}");
                return(RedirectToAction(nameof(Index)));
            }
            _logger.LogError($"Error with ModelState validation. User {_user} ");
            return(View(programCreateModel));
        }
예제 #3
0
        public IActionResult Create()
        {
            var model = new ProgramCreateModel();

            return(View(model));
        }