public IActionResult UpdateAudit([FromBody] AuditViewModel audit)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    AuditServiceResponseModel updateMethodServiceResponseModel = _iaudit.UpdateAuditService(audit);

                    if (updateMethodServiceResponseModel.code == responseCode.ErrorOccured)
                    {
                        return(BadRequest(updateMethodServiceResponseModel.audit, updateMethodServiceResponseModel.Message, updateMethodServiceResponseModel.code));
                    }
                    else if (updateMethodServiceResponseModel.code == responseCode.Successful)
                    {
                        return(Ok(updateMethodServiceResponseModel.audit, updateMethodServiceResponseModel.Message, updateMethodServiceResponseModel.code));
                    }
                    else
                    {
                        return(BadRequest(null, "Error Occured", responseCode.ErrorOccured));
                    }
                }
                return(BadRequest(null, "Null Entity", responseCode.ErrorOccured));
            }
            catch (Exception ex)
            {
                return(BadRequest(ex));
            }
        }
        public IActionResult DeleteAudit(Guid id)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    AuditServiceResponseModel deleteResponseReciever = _iaudit.AuditDeleteService(id);

                    if (deleteResponseReciever.code == responseCode.ErrorOccured)
                    {
                        return(BadRequest(deleteResponseReciever.audit, deleteResponseReciever.Message, deleteResponseReciever.code));
                    }
                    else if (deleteResponseReciever.code == responseCode.Successful)
                    {
                        return(Ok(deleteResponseReciever.audit, deleteResponseReciever.Message, deleteResponseReciever.code));
                    }
                    else
                    {
                        return(BadRequest(null, "Error Occured", responseCode.ErrorOccured));
                    }
                }
                return(BadRequest(null, "Null Entity", responseCode.ErrorOccured));
            }
            catch (Exception ex)
            {
                return(BadRequest(ex));
            }
        }
        public IActionResult GetAuditById(Guid id)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    AuditServiceResponseModel getByIdResponseReciever = _iaudit.GetAuditByIdService(id);

                    if (getByIdResponseReciever.code == responseCode.ErrorOccured)
                    {
                        return(BadRequest(getByIdResponseReciever.audit, getByIdResponseReciever.Message, getByIdResponseReciever.code));
                    }
                    else if (getByIdResponseReciever.code == responseCode.Successful)
                    {
                        return(Ok(getByIdResponseReciever.audit, getByIdResponseReciever.Message, getByIdResponseReciever.code));
                    }
                    else
                    {
                        return(BadRequest("Error Occured", responseCode.ErrorOccured));
                    }
                }
                return(BadRequest("Null Entity", responseCode.ErrorOccured));
            }
            catch (Exception ex)
            {
                return(BadRequest(ex));
            }
        }
Example #4
0
        //this service adds logs to the audit rail
        public AuditServiceResponseModel AuditCreationService(AuditViewModel audit)
        {
            try
            {
                //unit of work is used to replace _context.
                Audit_Rail auditToBeCreated;

                Company checkIfCompanyExists = UnitOfWork.GetRepository <Company>().Single(p => p.Id == audit.Company_Id && p.Status == EntityStatus.Active);
                if (checkIfCompanyExists != null)
                {
                    User checkIfUserExists = UnitOfWork.GetRepository <User>().Single(p => p.Id == audit.User_Id && p.Status == EntityStatus.Active);
                    if (checkIfUserExists != null)
                    {
                        auditToBeCreated = new Audit_Rail
                        {
                            Company_Id         = audit.Company_Id,
                            User_Id            = audit.User_Id,
                            Activity           = audit.Activity,
                            Status             = EntityStatus.Active,
                            CreatedAt          = DateTime.Now,
                            CreatedAtTimeStamp = DateTime.Now.ToTimeStamp(),
                            UpdatedAt          = DateTime.Now,
                            UpdatedAtTimeStamp = DateTime.Now.ToTimeStamp()
                        };
                        UnitOfWork.GetRepository <Audit_Rail>().Add(auditToBeCreated);
                        UnitOfWork.SaveChanges();

                        auditModel = new AuditServiceResponseModel()
                        {
                            audit = auditToBeCreated, Message = "Entity Created Successfully", code = responseCode.Successful
                        };
                        return(auditModel);
                    }
                    else
                    {
                        auditModel = new AuditServiceResponseModel()
                        {
                            audit = null, Message = "User Does Not Exist", code = responseCode.ErrorOccured
                        };
                        return(auditModel);
                    }
                }
                else
                {
                    auditModel = new AuditServiceResponseModel()
                    {
                        audit = null, Message = "Company Does Not Exist", code = responseCode.ErrorOccured
                    };
                    return(auditModel);
                }
            }
            catch (Exception ex)
            {
                _loggerManager.LogError(ex.Message);
                throw;
            }
        }
Example #5
0
        //this service fetches logs by there id
        public AuditServiceResponseModel GetAuditByIdService(Guid id)
        {
            try
            {
                Audit_Rail audit = UnitOfWork.GetRepository <Audit_Rail>().Single(p => p.Id == id);

                //since i cant send company directly, i get the company and pass the values i need into the companyViewModel which i then return
                //CompanyViewModel companyViewModel = new CompanyViewModel
                //{
                //    Company_Name = company.Company_Name,
                //    Id = company.Id
                //};

                if (audit != null)
                {
                    if (audit.Status == EntityStatus.Active)
                    {
                        auditModel = new AuditServiceResponseModel()
                        {
                            audit = audit, Message = "Entity Fetched Successfully", code = responseCode.Successful
                        };
                        return(auditModel);
                    }
                    else
                    {
                        auditModel = new AuditServiceResponseModel()
                        {
                            audit = null, Message = "Entity Does Not Exist", code = responseCode.ErrorOccured
                        };
                        return(auditModel);
                    }
                }
                auditModel = new AuditServiceResponseModel()
                {
                    audit = null, Message = "Entity Does Not Exist", code = responseCode.ErrorOccured
                };
                return(auditModel);
            }
            catch (Exception ex)
            {
                _loggerManager.LogError(ex.Message);
                throw ex;
            }
        }
Example #6
0
        //this service deletes logs
        public AuditServiceResponseModel AuditDeleteService(Guid id)
        {
            try
            {
                Audit_Rail audit = UnitOfWork.GetRepository <Audit_Rail>().Single(p => p.Id == id);
                if (audit == null)
                {
                    auditModel = new AuditServiceResponseModel()
                    {
                        audit = null, Message = "Entity Does Not Exist", code = responseCode.ErrorOccured
                    };
                    return(auditModel);
                }
                else
                {
                    if (audit.Status == EntityStatus.Active)
                    {
                        audit.Status = EntityStatus.InActive;
                        UnitOfWork.GetRepository <Audit_Rail>().Update(audit);
                        UnitOfWork.SaveChanges();

                        auditModel = new AuditServiceResponseModel()
                        {
                            audit = audit, Message = "Entity Deleted Successfully", code = responseCode.Successful
                        };
                        return(auditModel);
                    }
                    else
                    {
                        auditModel = new AuditServiceResponseModel()
                        {
                            audit = null, Message = "Entity Does Not Exist", code = responseCode.ErrorOccured
                        };
                        return(auditModel);
                    }
                }
            }
            catch (Exception ex)
            {
                _loggerManager.LogError(ex.Message);
                throw;
            }
        }
Example #7
0
        //this service updates logs
        public AuditServiceResponseModel UpdateAuditService(AuditViewModel audit)
        {
            try
            {
                Audit_Rail toBeUpdatedAudit = UnitOfWork.GetRepository <Audit_Rail>().Single(p => p.Id == audit.Id);
                if (toBeUpdatedAudit == null)
                {
                    auditModel = new AuditServiceResponseModel()
                    {
                        audit = null, Message = "Entity Does Not Exist", code = responseCode.ErrorOccured
                    };
                    return(auditModel);
                }
                else
                {
                    if (toBeUpdatedAudit.Status == EntityStatus.Active)
                    {
                        Company checkIfCompanyExists = UnitOfWork.GetRepository <Company>().Single(p => p.Id == audit.Company_Id && p.Status == EntityStatus.Active);
                        if (checkIfCompanyExists != null)
                        {
                            User checkIfUserExists = UnitOfWork.GetRepository <User>().Single(p => p.Id == audit.User_Id && p.Status == EntityStatus.Active);
                            if (checkIfCompanyExists != null)
                            {
                                //here i will assign directly what i want to update to the model instead of creating a new instance
                                //toBeUpdatedUser.Company_Id = user.Company_Id;

                                toBeUpdatedAudit.Activity           = audit.Activity;
                                toBeUpdatedAudit.Status             = EntityStatus.Active;
                                toBeUpdatedAudit.UpdatedAt          = DateTime.Now;
                                toBeUpdatedAudit.UpdatedAtTimeStamp = DateTime.Now.ToTimeStamp();
                                UnitOfWork.GetRepository <Audit_Rail>().Update(toBeUpdatedAudit);;
                                UnitOfWork.SaveChanges();

                                auditModel = new AuditServiceResponseModel()
                                {
                                    audit = toBeUpdatedAudit, Message = "Entity Updated Successfully", code = responseCode.Successful
                                };
                                return(auditModel);
                            }
                            else
                            {
                                auditModel = new AuditServiceResponseModel()
                                {
                                    audit = null, Message = "user Do Not Exist", code = responseCode.ErrorOccured
                                };
                                return(auditModel);
                            }
                        }
                        else
                        {
                            auditModel = new AuditServiceResponseModel()
                            {
                                audit = null, Message = "Company Do Not Exist", code = responseCode.ErrorOccured
                            };
                            return(auditModel);
                        }
                    }
                    else
                    {
                        auditModel = new AuditServiceResponseModel()
                        {
                            audit = null, Message = "Entity Does Not Exist", code = responseCode.ErrorOccured
                        };
                        return(auditModel);
                    }
                }
            }
            catch (Exception ex)
            {
                _loggerManager.LogError(ex.Message);
                throw;
            }
        }