Exemple #1
0
        public async Task <IActionResult> Register(RegisterViewModel child, List <int> options)
        {
            if (!ModelState.IsValid)
            {
                var items = await _userServices.GetAllGradesAsync();

                ViewData["GradeList"]  = items;
                ViewData["Error"]      = true;
                ViewData["EmployeeId"] = child.EmployeeId;

                return(View(child));
            }

            var birthday = DateConvertor.ToMiladi(child.Birthday);
            var maxDate  = _settingServices.GetBirthDayLimitation();

            if (birthday < maxDate)
            {
                var items = await _userServices.GetAllGradesAsync();

                ViewData["GradeList"]  = items;
                ViewData["Error"]      = true;
                ViewData["EmployeeId"] = child.EmployeeId;

                ModelState.AddModelError("", "تاریخ تولد صحیح نمی باشد");
                return(View(child));
            }


            child.ChildId = await _userServices.AddChildAsync(child);

            await _userServices.AddOptionForChild(child.ChildId, options);

            if (child.OptionalDetailsSampadImages != null)
            {
                child.OptionalSampadDetail = new OptionalDetails()
                {
                    DetailTitleId = 1,
                    ChildId       = child.ChildId
                };

                await _userServices.AddOptionalDetails(child.ChildId, child.OptionalSampadDetail,
                                                       child.OptionalDetailsSampadImages);
            }

            if (child.OptionalDetailsUniversityImages != null)
            {
                child.OptionalUniversityDetails = new OptionalDetails()
                {
                    DetailTitleId = 2,
                    ChildId       = child.ChildId
                };

                await _userServices.AddOptionalDetails(child.ChildId, child.OptionalUniversityDetails,
                                                       child.OptionalDetailsUniversityImages);
            }

            return(Redirect("/Userpanel"));
        }
Exemple #2
0
        public async Task <IActionResult> Create([Bind("ChildId,EmployeeId,FullName,ReportCardId,Image,GradeId,IsDelete")] Child child)
        {
            if (ModelState.IsValid)
            {
                await _userServices.AddChildAsync(child);

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["EmployeeId"] = new SelectList(_userServices.GetEmployees(), "EmployeeId", "FullName", child.EmployeeId);
            ViewData["GradeId"]    = new SelectList(_userServices.GetAllGrade(), "GradeId", "GradeTitle", child.GradeId);
            return(View(child));
        }