Пример #1
0
        public async Task <ActionResult> CreateSubject(SubjectViewModel subject)
        {
            string currentUserId = System.Web.HttpContext.Current.User.Identity.GetUserId();

            if (currentUserId == null)
            {
                return(new HttpUnauthorizedResult());
            }
            if (ModelState.IsValid)
            {
                SubjectDTO subjectDTO = new SubjectDTO
                {
                    SubjectName = subject.Name,
                    Description = subject.Description,
                    IsApproved  = subject.IsApproved
                };
                OperationDetails operationDetails = await SubjectService.CreateAsync(subjectDTO, currentUserId);

                if (operationDetails.Succedeed)
                {
                    return(PartialView("Report", operationDetails));
                }
                else
                {
                    ModelState.AddModelError(operationDetails.Property, operationDetails.Message);
                    return(PartialView("Report", operationDetails));
                }
            }
            ViewBag.Message = "Non valid";
            return(PartialView("~/Views/Admin/Subject/CreateSubject.cshtml", subject));
        }
Пример #2
0
 /// <summary>
 /// 创建科目
 /// </summary>
 /// <param name="Name"></param>
 /// <param name="gradeId"></param>
 /// <returns></returns>
 public static async Task CreateSubject(string Name, Guid gradeId)
 {
     using (var subSvc = new SubjectService())
     {
         await subSvc.CreateAsync(new Subject()
         {
             Name    = Name,
             GradeId = gradeId
         });
     }
 }
        public async Task <ActionResult> Create(Subject subject)
        {
            if (ModelState.IsValid)
            {
                await _service.CreateAsync(subject);

                return(RedirectToAction(nameof(Index)));
            }
            else
            {
                return(View(subject));
            }
        }
        public async Task <ActionResult> SuggestSubject(SubjectViewModel subject)
        {
            try
            {
                //I. Check.
                string currentUserId = System.Web.HttpContext.Current.User.Identity.GetUserId();
                if (currentUserId == null)
                {
                    return(new HttpUnauthorizedResult());
                }

                // II. Create a new subject.
                if (ModelState.IsValid)
                {
                    SubjectDTO subjectDTO = new SubjectDTO
                    {
                        SubjectName = subject.Name,
                        Description = subject.Description,
                        IsApproved  = false
                    };
                    OperationDetails operationDetails = await SubjectService.CreateAsync(subjectDTO, currentUserId);

                    if (operationDetails.Succedeed)
                    {
                        return(PartialView("Report", operationDetails));
                    }
                    else
                    {
                        ModelState.AddModelError(operationDetails.Property, operationDetails.Message);
                        return(PartialView("Report", operationDetails));
                    }
                }

                // III.
                ViewBag.Message = "Non valid";
                return(PartialView(subject));
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }