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"));
        }