コード例 #1
0
        public async Task <IActionResult> NewPatient(PatientDto model, List <IFormFile> files)
        {
            var ee = "";

            if (ModelState.IsValid)
            {
                try
                {
                    string succed;

                    succed = await _patient.Create(model);

                    if (succed == "true")
                    {
                        var user = await userManager.FindByNameAsync(model.EmailAddress);

                        var user1 = await _context.Patients.FirstOrDefaultAsync(x => x.UserId == user.Id);

                        //try to update the Patient Reg
                        //Patient Reg
                        string numberid = user1.Id.ToString("D3");
                        user1.PatientReg = "PAT/" + numberid;

                        //try to update the user profile pict
                        //profile pic upload
                        var fileName = await _upload.UploadFile(files, _env);

                        user1.ProfilePicture        = "/Uploads/" + fileName;
                        _context.Entry(user1).State = EntityState.Modified;
                        await _context.SaveChangesAsync();



                        TempData["success"] = "Patient with Username " + model.Fullname + "Added Successfully";
                        return(RedirectToAction("NewPatient"));
                    }
                    else
                    {
                        TempData["error1"] = succed;
                    }
                }
                catch (Exception e)
                {
                    ee = e.ToString();
                }
            }
            var allErrors = ModelState.Values.SelectMany(v => v.Errors);

            TempData["error"]        = "Creation of new Patient not successful" + ee;
            ViewData["BloodGroupId"] = new SelectList(_context.BloodGroup, "Id", "Name", model.BloodGroupId);
            return(View(model));
        }