public async Task <IActionResult> PutUtenti(UtentiDto utentiDto) { try { if (utentiDto == null) { return(NotFound()); } utentiDto.UteModUteId = this.LoggedInUserId(); await _userManager.Update(utentiDto, utentiDto.UtentiAbilitazioniDto); // creating the azioni object passing the related details and description. var azioniDto = _utilityManager.GetAzioniDtoObject(User, "update", "utenti"); // logging the activity record by the user. await _azioniManager.AzioniInsert(azioniDto); return(Ok()); } catch (Exception x) { // Code block of Exception handling and logging into log_operazione table. var errorObj = await _utilityManager.ReturnErrorObj(x, User, "Update Utenti"); // Returning the error object. return(BadRequest(errorObj)); } }
public async Task <IActionResult> PostUtenti([FromBody] UtentiDto utentiDto) { try { if (utentiDto == null) { return(NotFound()); } var isValidPass = _userManager.IsValidPass(utentiDto.UtePassword); if (!isValidPass) { var result = new { error = "Validation Failed", error_type = "", message = "Password should have 1 digit, 1 symbol, 1 capital letter and 1 small letter" }; return(BadRequest(result)); } //var userHasSamePassForSameUsername = _talentBllWrapper.UtentiBll.HasSamePassForSameUsername(utentiDto.UteId, utentiDto.UtePassword); var userHasSamePassForSameUsername = await _userManager.HasSamePassForSameUsername(utentiDto.UteId, utentiDto.UtePassword); if (userHasSamePassForSameUsername) { var result = new { error = "Validation Failed", error_type = "", message = "There's a user having same username and password for some other client" }; return(BadRequest(result)); } utentiDto.UteInsUteId = this.LoggedInUserId(); await _userManager.Insert(utentiDto, utentiDto.UtentiAbilitazioniDto); // creating the azioni object passing the related details and description. var azioniDto = _utilityManager.GetAzioniDtoObject(User, "add", "utenti"); // logging the activity record by the user. await _azioniManager.AzioniInsert(azioniDto); return(Ok()); } catch (Exception x) { // Code block of Exception handling and logging into log_operazione table. var errorObj = await _utilityManager.ReturnErrorObj(x, User, "Insert new Utenti"); // Returning the error object. return(BadRequest(errorObj)); } }
public async Task <string> Insert(UtentiDto utentiDto, List <UtentiAbilitazioniDto> userAuthDtoList) { try { // Model class mapping from UtentiDto to Utenti. var utenti = _mapper.Map <UtentiDto, Utenti>(utentiDto); utenti.UteAttivo = "S"; utenti.UteModUteId = utentiDto.UteInsUteId; utenti.UteInsTimestamp = DateTime.Now; utenti.UteModTimestamp = DateTime.Now; // Setting some default value which aren't belonges to dto object. utenti.UteTipoClientEmail = "outlook"; utenti.UteRicerchePortaliMaxNum = 0; utenti.UteDeveloper = "N"; utenti.UteLimiteMaxSms = 0; utenti.UteModalitaDebug = ""; // Initialazing the UtentiAbilitazioni. List <UtentiAbilitazioni> userAuthList = new List <UtentiAbilitazioni>(); // Loop to map from UtentiAbilitazioniDto to UtentiAbilitazioni. foreach (var userAuthDto in userAuthDtoList) { if (userAuthDto.UteabAbilitato == "S") { // Model class mapping from UtentiAbilitazioniDto to UtentiAbilitazioni. var utentiAbilitazioni = _mapper.Map <UtentiAbilitazioniDto, UtentiAbilitazioni>(userAuthDto); utentiAbilitazioni.UteabUteId = utenti.UteId; utentiAbilitazioni.UteabInsUteId = utenti.UteInsUteId; utentiAbilitazioni.UteabModUteId = utenti.UteInsUteId; utentiAbilitazioni.UteabProcedura = userAuthDto.TipoabilitProcedura; utentiAbilitazioni.UteabInsTimestamp = DateTime.Now; utentiAbilitazioni.UteabModTimestamp = DateTime.Now; utentiAbilitazioni.UteabCliId = utenti.UteCliId; // Adding the mapped object into the list. userAuthList.Add(utentiAbilitazioni); } } // Passing the data to dal. _unitOfWork.Users.Add(utenti); _unitOfWork.UtentiAbilitazioni.AddRange(userAuthList); // Returning the recently inserted utenti id. await _unitOfWork.CompleteAsync(); return(utenti.UteId); } catch (Exception ex) { throw; } }
public async Task <string> Update(UtentiDto utentiDto, List <UtentiAbilitazioniDto> userAuthDtoList) { // Model class mapping from UtentiDto to Utenti. var utenti = await _unitOfWork.Users.FirstOrDefaultAsync(u => u.UteId.Equals(utentiDto.UteId) && u.UteCliId.Equals(utentiDto.UteCliId)); _mapper.Map(utentiDto, utenti); utenti.UteModTimestamp = DateTime.Now; // Setting null for empty string of role. if (utenti.UteRuolo == "") { utenti.UteRuolo = null; } // Initialazing the UtentiAbilitazioni. List <UtentiAbilitazioni> userAuthList = new List <UtentiAbilitazioni>(); // Loop to map from UtentiAbilitazioniDto to UtentiAbilitazioni. foreach (var userAuthDto in userAuthDtoList) { // Model class mapping from UtentiAbilitazioniDto to UtentiAbilitazioni. var utentiAbilitazioni = _mapper.Map <UtentiAbilitazioniDto, UtentiAbilitazioni>(userAuthDto); utentiAbilitazioni.UteabInsUteId = utenti.UteModUteId; utentiAbilitazioni.UteabModUteId = utenti.UteModUteId; utentiAbilitazioni.UteabInsTimestamp = DateTime.Now; utentiAbilitazioni.UteabModTimestamp = DateTime.Now; utentiAbilitazioni.UteabProcedura = userAuthDto.TipoabilitProcedura; utentiAbilitazioni.UteabUteId = utenti.UteId; utentiAbilitazioni.UteabCliId = utenti.UteCliId; // Adding the mapped object into the list. userAuthList.Add(utentiAbilitazioni); } foreach (var _userAuth in userAuthList) { // Checking whether this authentication is already exist for this user/utenti or not. var records = await _unitOfWork.UtentiAbilitazioni. FindAsync(c => c.UteabUteId == _userAuth.UteabUteId && c.UteabProcedura == _userAuth.UteabProcedura && c.UteabCliId == _userAuth.UteabCliId); // If doesn't exists and the authentication is checked then that auth is added for that utenti. if (records.Count() == 0 && _userAuth.UteabAbilitato == "S") { _unitOfWork.UtentiAbilitazioni.Add(_userAuth); } else { // If exist, then update the status and modified time of that auth for that utenti. if (records.Count() != 0) { var updatableRow = await _unitOfWork.UtentiAbilitazioni .FirstOrDefaultAsync(c => c.UteabUteId == _userAuth.UteabUteId && c.UteabProcedura == _userAuth.UteabProcedura && c.UteabCliId == _userAuth.UteabCliId); updatableRow.UteabAbilitato = _userAuth.UteabAbilitato; } } } await _unitOfWork.CompleteAsync(); // Returning the recently updated utenti id. return(utentiDto.UteId); }