示例#1
0
        public async Task <IActionResult> AddSubject(SubjectBindingModel subjectBindingModel)
        {
            if (!ModelState.IsValid)
            {
                return(RedirectToAction("Index"));
            }

            var subjectCategoryModel =
                await _subjectCategoryService.GetSubjectCategoryById(subjectBindingModel.SubjectCategoryId);

            if (subjectCategoryModel == null)
            {
                return(BadRequest("Could not find the subject category."));
            }

            var subjectModel = new SubjectModel
            {
                Title = subjectBindingModel.Title,
                SubjectCategoryModel = subjectCategoryModel
            };

            var successful = await _subjectService.AddSubjectAsync(subjectModel);

            if (!successful)
            {
                return(BadRequest("Could not add the subject"));
            }

            return(RedirectToAction("Index"));
        }
        public async Task <IActionResult> AddSubject(Subject subject)
        {
            var subjectObject = await _subjectService.AddSubjectAsync(subject);

            if (subjectObject == null)
            {
                return(BadRequest());
            }

            return(Ok(subjectObject));
        }
        private async void NewSubjectOnClick(object obj)
        {
            var dialogViewModel = new CreateOrEditSubjectDialogViewModel();

            if (dialogViewModel.ShowDialog() == true)
            {
                var subject = new Subject(dialogViewModel.SubjectName, dialogViewModel.SubjectCredit);

                Subjects.Add(subject);
                await _subjectService.AddSubjectAsync(subject);
            }
        }
        public async Task <bool> AddSubjectAsync(ISubject subject)
        {
            try
            {
                var user = await LoginUserHelperManager.GetCurrentUser();

                await _subjectService.AddSubjectAsync(subject);

                return(true);
            }
            catch (Exception ex)
            {
                return(false);
            }
        }
        public async void Add_Subject_Test()
        {
            var subject = new Subject()
            {
                Name = "ICT"
            };


            var savedSubject = await _subjectService.AddSubjectAsync(subject);

            //check the savedSubject Id
            //savedSubject.Id.Should().Be(1);

            //check the savedSubject Name
            savedSubject.Name.Should().Be("ICT", "Subject name is ICT");
        }
        public ActionResult Create([Bind(Include = "Name, Credit")] Subject subject)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    _subjectService.AddSubjectAsync(subject);

                    return(RedirectToAction("Index"));
                }
            }
            catch
            {
                ModelState.AddModelError("", "Unable to save changes");
            }

            return(View(subject));
        }
示例#7
0
        public async Task <IHttpActionResult> AddSubject([FromBody] SubjectDTO SubjectModel)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var newSubjectId = await SubjectService.AddSubjectAsync(SubjectModel);

            if (newSubjectId != 0)
            {
                return(Ok(newSubjectId));
            }
            else
            {
                return(NotFound());
            }
        }