public async Task <JsonResult> Students([FromBody] StudentForm model) { string err = ""; string status = ""; bool r = false; _loggedinuser = await _manager.GetUserAsync(User); _logger.LogInformation($"begin saving new student with name = {model.FirstName}, admission date = {model.AdmissionDate.ToShortDateString()} dob = {model.DOB.ToShortDateString()}"); if (!ModelState.IsValid) { _logger.LogInformation("Model error while creating student"); err = "Model error while creating student"; status = "Student could not be created"; } ImgDoc pic = new ImgDoc(); if (!string.IsNullOrEmpty(model.StudentPic)) { string fname = model.StudentPic.Split('~')[0]; string type = model.StudentPic.Split('~')[1].Split(',')[0].Split(':')[1]; string base64 = model.StudentPic.Split('~')[1].Split(',')[1]; pic.name = fname.Split('.')[0]; pic.fileExtension = fname.Split('.')[fname.Split('.').Length - 1]; pic.contentType = type; pic.content = base64; } else { pic = null; } var u = new mpsUser { FirstName = model.FirstName, MiddleName = model.MiddleName, LastName = model.LastName, Email = model.Email, UserName = model.UserName, PhoneNumber = model.PhoneNumber, Gender = model.Gender, DOB = model.DOB, Address1 = model.Address1, Address2 = model.Address2, UserPic = pic }; try{ mpsUserResult res = await u.CreatempsUserAsync(_manager, u, model.Password, "Student"); if (!String.IsNullOrEmpty(res.newUserId)) { bool b = await _repo.SaveStudentAsync(model, res.newUserId, "", _loggedinuser); if (b) { status = "New student " + model.FirstName + " is created"; r = true; // try{ // bool mail = _mailer.SendUserEmail(MAILTYPE.StudentCreated,model); // bool text = _msg91.SendUserText(TEXTTYPE.StudentCreated,model); // if(!mail){ // _logger.LogError($"error sending mail to { model.Email }"); // status += "\n Not able to send confirmation email"; // } // if(!text){ // _logger.LogError($"error sending sms to { model.PhoneNumber }"); // status += "\n Not able to send confirmation text message"; // } // } // catch(Exception ex) // { // _logger.LogError($"Exception when sending confirmation{ex.Message}"); // status += "\n But not able to send confirmation"; // } } } else { _logger.LogInformation("New user could not be created "); status = "Student could not be created"; foreach (IdentityError s in res.errors) { err += s.Code + " - " + s.Description + " - "; } } } catch (Exception ex) { ModelState.AddModelError("", ex.Message); } return(Json(new { res = r, status = status, errors = err })); }