public async Task <bool> AddDeduction([FromBody] DeductionsForm deductions) { bool res = false; if (ModelState.IsValid) { _loggedinuser = await _manager.GetUserAsync(User); if (!deductions.id.HasValue) { //add res = await _repo.addDeductionAsync(deductions, _loggedinuser); _logger.LogInformation($"Deduction {deductions.deductionName} saved by {_loggedinuser.UserName}"); } else { //update res = await _repo.updateDeductionAsync(deductions, _loggedinuser); _logger.LogInformation($"Deduction {deductions.deductionName} Updated by {_loggedinuser.UserName}"); } } return(res); }
public async Task <bool> AddExpenseHeader([FromBody] ExpenseHeaderForm expense) { bool res = false; if (ModelState.IsValid) { _loggedinuser = await _manager.GetUserAsync(User); if (!expense.expenseId.HasValue) { //add res = await _repo.addExpenseHeaderAsync(expense, _loggedinuser); _logger.LogInformation($"Expense {expense.expenseName} saved by {_loggedinuser.UserName}"); } else { //update res = await _repo.updateExpenseHeaderAsync(expense, _loggedinuser); _logger.LogInformation($"Expense {expense.expenseName} Updated by {_loggedinuser.UserName}"); } } return(res); }
public async Task <JsonResult> UpdateStudent([FromBody] StudentForm student) { string err = ""; string status = ""; bool r = false; _logger.LogInformation($"update started for {student.FirstName} {student.LastName}"); if (ModelState.IsValid) { _loggedinuser = await _manager.GetUserAsync(User); _logger.LogInformation($"By {_loggedinuser.UserName}"); bool res = await _repo.updateStudentAsync(student, _loggedinuser); if (res) { status = "Student " + student.FirstName + " is Updated"; r = true; // try{ // bool mail = _mailer.SendUserEmail(MAILTYPE.StudentEdited,student); // bool text = _msg91.SendUserText(TEXTTYPE.StudentEdited,student); // if(!mail){ // _logger.LogError($"error sending mail to { student.Email }"); // status += "\n Not able to send confirmation email"; // } // if(!text){ // _logger.LogError($"error sending sms to { student.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 { status = "Student could not be updated"; } } else { err = "Model error while creating student"; status = "Student could not be updated"; } _logger.LogInformation(status); return(Json(new { res = r, status = status, errors = err })); }
public async Task <bool> updateSlab([FromBody] SlabForm slab) { bool res = false; _loggedinuser = await _manager.GetUserAsync(User); if (ModelState.IsValid) { res = await _repo.updateSlabAsync(slab, _loggedinuser); if (res) { _logger.LogInformation($"Slab {slab.slabName} is updated by {_loggedinuser.UserName}"); } } return(res); }
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 })); }
public async Task <JsonResult> UpdateStaff([FromBody] StaffForm staff) { string err = ""; string status = ""; bool r = false; _logger.LogInformation($"update started for {staff.FirstName} {staff.LastName}"); if (ModelState.IsValid) { _loggedinuser = await _manager.GetUserAsync(User); _logger.LogInformation($"By {_loggedinuser.UserName}"); bool res = await _repo.updateStaffAsync(staff, _loggedinuser); if (res) { status = "Staff " + staff.FirstName + " is Updated"; r = true; //update the role var su = await _manager.FindByNameAsync(staff.UserName); var roles = await _manager.GetRolesAsync(su); if (!roles.Contains(staff.staffrole)) { await _manager.RemoveFromRolesAsync(su, roles); var result = await _manager.AddToRoleAsync(su, staff.staffrole); if (!result.Succeeded) { status = "\n The role could not be updated"; foreach (var e in result.Errors) { string.Concat(err, ", "); string.Concat(err, e.Description); } } else { _logger.LogError($"Error while updating role {err}"); } } // try{ // bool mail = _mailer.SendUserEmail(MAILTYPE.StaffEdited,staff); // bool text = _msg91.SendUserText(TEXTTYPE.StaffEdited,staff); // if(!mail){ // _logger.LogError($"error sending mail to { staff.Email }"); // status += "\n Not able to send confirmation email"; // } // if(!text){ // _logger.LogError($"error sending sms to { staff.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 any confirmation"; // } } else { status = "Staff/Teacher could not be updated"; } } else { err = "Model error while updating Staff/Teacher"; status = "Staff/Teacher could not be updated"; } _logger.LogInformation(status); return(Json(new { res = r, status = status, errors = err })); }