Exemplo n.º 1
0
        public async Task <IActionResult> Update(int id, [FromBody] UsersUpdateDTO UserDTO)
        {
            try
            {
                _logger.LogInfo($"User detail update with id:{id}");
                if (id < 1 || UserDTO == null || id != UserDTO.id)
                {
                    _logger.LogWarn("User update failed with bad data");
                    return(BadRequest());
                }
                var isExist = await _UserRepository.isExist(id);

                if (!isExist)
                {
                    _logger.LogWarn($"User with id:{id} was not found");
                    return(NotFound());
                }
                if (!ModelState.IsValid)
                {
                    _logger.LogWarn("User data was incomplete");
                    return(BadRequest(ModelState));
                }
                var User      = _Mapper.Map <Users>(UserDTO);
                var isSuccess = await _UserRepository.Update(User);

                if (!isSuccess)
                {
                    return(InternalError("User operation failed"));
                }
                _logger.LogInfo("User updated");
                Audit_logs audit = new Audit_logs()
                {
                    uid      = User.id,
                    action   = "Update",
                    log      = $"{User.id} has Updated,Name:{User.username},FirstName:{User.fname},LastName:{User.lname},Email:{User.Email},DOB:{User.dob},Phone:{User.Phone}",
                    datetime = DateTime.Now
                };
                await _audit_Logs.Create(audit);

                return(NoContent());
            }
            catch (Exception ex)
            {
                return(InternalError($"{ex.Message}-{ex.InnerException}"));
            }
        }
        public async Task <IActionResult> Update(int id, [FromBody] JsonDetailsKeyUpdateDTO jsonDetailsUpdatedDTO)
        {
            try
            {
                _logger.LogInfo($"Json detail update with id:{id}");
                if (id < 1 || jsonDetailsUpdatedDTO == null || id != jsonDetailsUpdatedDTO.JsonKeyID)
                {
                    _logger.LogWarn("Json records update failed with bad data");
                    return(BadRequest());
                }
                var isExist = await _JsonDetailsKeyRepository.isExist(id);

                if (!isExist)
                {
                    _logger.LogWarn($"Json record with id:{id} was not found");
                    return(NotFound());
                }
                if (!ModelState.IsValid)
                {
                    _logger.LogWarn("Json data was incomplete");
                    return(BadRequest(ModelState));
                }
                var jsonrecord = _Mapper.Map <JsonDetailsKey>(jsonDetailsUpdatedDTO);
                var isSuccess  = await _JsonDetailsKeyRepository.Update(jsonrecord);

                if (!isSuccess)
                {
                    return(InternalError("Json record update operation failed"));
                }
                _logger.LogInfo("Json records updated");
                Audit_logs audit = new Audit_logs()
                {
                    jsonKeyid = jsonrecord.JsonKeyID,
                    action    = "Update",
                    log       = $"Json records has Updated,Key:{jsonrecord.Keys},KeyValues1:{jsonrecord.KeyValues1},KeyValues2:{jsonrecord.KeyValues2}",
                    datetime  = DateTime.Now
                };
                await _audit_Logs.Create(audit);

                return(NoContent());
            }
            catch (Exception ex)
            {
                return(InternalError($"{ex.Message}-{ex.InnerException}"));
            }
        }
        public async Task <IActionResult> Delete(int id)
        {
            try
            {
                _logger.LogInfo($"Json detail delete with id:{id}");
                if (id < 1)
                {
                    _logger.LogWarn("Json details not avaible");
                    return(BadRequest());
                }
                var isExist = await _JsonDetailsKeyRepository.isExist(id);

                if (!isExist)
                {
                    _logger.LogWarn($"Json details with id:{id} was not found");
                    return(NotFound());
                }
                var jsonrecord = await _JsonDetailsKeyRepository.FindById(id);

                var isSuccess = await _JsonDetailsKeyRepository.Delete(jsonrecord);

                if (!isSuccess)
                {
                    return(InternalError("Json records delete failed"));
                }
                _logger.LogInfo("Json records delete");
                Audit_logs audit = new Audit_logs()
                {
                    jsonKeyid = jsonrecord.JsonKeyID,
                    action    = "Delete",
                    log       = $"Json records has Deleted,Key:{jsonrecord.Keys},KeyValues1:{jsonrecord.KeyValues1},KeyValues2:{jsonrecord.KeyValues2}",
                    datetime  = DateTime.Now
                };
                await _audit_Logs.Create(audit);

                return(NoContent());
            }
            catch (Exception ex)
            {
                return(InternalError($"{ex.Message}-{ex.InnerException}"));
            }
        }
Exemplo n.º 4
0
        public async Task <IActionResult> Delete(int id)
        {
            try
            {
                _logger.LogInfo($"User detail delete with id:{id}");
                if (id < 1)
                {
                    _logger.LogWarn("User details not avaible");
                    return(BadRequest());
                }
                var isExist = await _UserRepository.isExist(id);

                if (!isExist)
                {
                    _logger.LogWarn($"User with id:{id} was not found");
                    return(NotFound());
                }
                var User = await _UserRepository.FindById(id);

                var isSuccess = await _UserRepository.Delete(User);

                if (!isSuccess)
                {
                    return(InternalError("User delete failed"));
                }
                _logger.LogInfo("User delete");
                Audit_logs audit = new Audit_logs()
                {
                    uid      = User.id,
                    action   = "Delete",
                    log      = $"{User.id} has deleted,Name:{User.username},FirstName:{User.fname},LastName:{User.lname},Email:{User.Email},DOB:{User.dob},Phone:{User.Phone}",
                    datetime = DateTime.Now
                };
                await _audit_Logs.Create(audit);

                return(NoContent());
            }
            catch (Exception ex)
            {
                return(InternalError($"{ex.Message}-{ex.InnerException}"));
            }
        }
        public async Task <IActionResult> Create([FromBody] JsonDetailsKeyCreateDTO jsonDetailsCreatedDTO)
        {
            try
            {
                _logger.LogInfo("Attempted submission attempted");

                if (jsonDetailsCreatedDTO == null)
                {
                    _logger.LogWarn("Empty request submitted");
                    return(BadRequest(ModelState));
                }
                if (!ModelState.IsValid)
                {
                    _logger.LogWarn("Json record data was incomplete");
                    return(BadRequest(ModelState));
                }
                var jsonrecord = _Mapper.Map <JsonDetailsKey>(jsonDetailsCreatedDTO);
                var isSuccess  = await _JsonDetailsKeyRepository.Create(jsonrecord);

                if (!isSuccess)
                {
                    return(InternalError("Json records creation failed"));
                }
                _logger.LogInfo("Json record created");
                Audit_logs audit = new Audit_logs()
                {
                    jsonKeyid = jsonrecord.JsonKeyID,
                    action    = "Create",
                    log       = $"Json records has created,Key:{jsonrecord.Keys},KeyValues1:{jsonrecord.KeyValues1},KeyValues2:{jsonrecord.KeyValues2}",
                    datetime  = DateTime.Now
                };
                await _audit_Logs.Create(audit);

                return(Created("Create", new { jsonrecord }));
            }
            catch (Exception ex)
            {
                return(InternalError($"{ex.Message}-{ex.InnerException}"));
            }
        }
Exemplo n.º 6
0
        public async Task <IActionResult> Create([FromBody] UsersCreateDTO UserDTO)
        {
            try
            {
                _logger.LogInfo("Attempted submission attempted");

                if (UserDTO == null)
                {
                    _logger.LogWarn("Empty request submitted");
                    return(BadRequest(ModelState));
                }
                if (!ModelState.IsValid)
                {
                    _logger.LogWarn("User data was incomplete");
                    return(BadRequest(ModelState));
                }
                var User      = _Mapper.Map <Users>(UserDTO);
                var isSuccess = await _UserRepository.Create(User);

                if (!isSuccess)
                {
                    return(InternalError("User creation failed"));
                }
                _logger.LogInfo("User created");
                Audit_logs audit = new Audit_logs()
                {
                    uid      = User.id,
                    action   = "Create",
                    log      = $"{User.id} has created,Name:{User.username},FirstName:{User.fname},LastName:{User.lname},Email:{User.Email},DOB:{User.dob},Phone:{User.Phone}",
                    datetime = DateTime.Now
                };
                await _audit_Logs.Create(audit);

                return(Created("Create", new { User }));
            }
            catch (Exception ex)
            {
                return(InternalError($"{ex.Message}-{ex.InnerException}"));
            }
        }
Exemplo n.º 7
0
        public async Task <IActionResult> DeleteUserRole([FromBody] DeleteAssignUserRole deleteassignUserRole)
        {
            try
            {
                _logger.LogInfo("Attempted submission attempted");

                if (deleteassignUserRole == null)
                {
                    _logger.LogWarn("Empty request submitted");
                    return(BadRequest(ModelState));
                }
                if (!ModelState.IsValid)
                {
                    _logger.LogWarn("User data was incomplete");
                    return(BadRequest(ModelState));
                }
                int UID       = _UserRoleRepository.DeleteAssignRoleUser(deleteassignUserRole, _userManager);
                var UserAudit = await _UserRepository.FindByUserName(deleteassignUserRole.username.ToString());

                var User_new = _Mapper.Map <IList <Users> >(UserAudit);
                _logger.LogInfo("Role has deleted");

                Audit_logs audit = new Audit_logs()
                {
                    uid      = User_new[0].id,
                    action   = "Delete User Role",
                    log      = $"{deleteassignUserRole.username} Role has deleted",
                    datetime = DateTime.Now
                };
                await _audit_Logs.Create(audit);

                return(NoContent());
            }
            catch (Exception ex)
            {
                return(InternalError($"{ex.Message}-{ex.InnerException}"));
            }
        }
Exemplo n.º 8
0
 public async Task <bool> Update(Audit_logs entity)
 {
     _db.audit_Logs.Update(entity);
     return(await Save());
 }
Exemplo n.º 9
0
 public async Task <bool> Delete(Audit_logs entity)
 {
     _db.audit_Logs.Remove(entity);
     return(await Save());
 }
Exemplo n.º 10
0
        public async Task <bool> Create(Audit_logs entity)
        {
            await _db.audit_Logs.AddAsync(entity);

            return(await Save());
        }