Пример #1
0
        public string ToString(LogsDTO logs)
        {
            string str;

            str = string.Format("{0}. {1}", logs.Id, logs.Name);
            return(str);
        }
Пример #2
0
        public async Task <LogsDTO> Logs(int pageNumer)
        {
            List <LogDTO> logDTO = _mapper.Map <List <LogDTO> >(await _log.Logs(pageNumer));
            LogsDTO       logs   = new LogsDTO()
            {
                Logs         = logDTO,
                RequestCount = _log.LogCount()
            };

            return(logs);
        }
Пример #3
0
        public LogsDTO Create(LogsDTO logs)
        {
            using (var entities = new DataContext())
            {
                Logs m = _mapper.Map <Logs>(logs);
                entities.Logs.Add(m);
                entities.SaveChanges();

                return(_mapper.Map <LogsDTO>(m));
            }
        }
Пример #4
0
        public ActionResult <LogsDTO> Put([FromBody] LogsDTO logs)
        {
            var value = _mapper.Map <Logs>(logs);
            var log   = _logsService.Atualizar(value);

            if (log != null)
            {
                var retorno = _mapper.Map <LogsDTO>(log);
                return(Ok(retorno));
            }
            else
            {
                return(NoContent());
            }
        }
Пример #5
0
        public async Task <Result> ReworkDocument(string id, string userRole, string userId, string comment)
        {
            Result result = new Result();

            try
            {
                var wfi = await _repo.GetFirstAsync <WorkflowInbox>(
                    filter : c => c.DocumentId == id);

                //update status of rework Document
                Document reworkDocument = await _repo.GetByIdAsync <Document>(Convert.ToInt32(wfi.DocumentId));

                reworkDocument.State = State.Rework;
                _repo.Update(reworkDocument);
                await _repo.SaveAsync();

                //update item in inbox
                wfi.ApproverRole = nameof(Role.USER);
                _repo.Update(wfi);
                await _repo.SaveAsync();

                result.Message = "Document has been successfully sent for rework.";

                //Add to logs
                LogsDTO dtoLogs = new LogsDTO
                {
                    DocId       = reworkDocument.Id.ToString(),
                    DataNumber  = reworkDocument.DataNumber,
                    UserId      = userId,
                    Action      = "Rework",
                    Description = "Document reworked by " + userRole,
                    Comment     = comment
                };

                var log = await _adminService.AddLogs(dtoLogs);

                result.Success = true;
            }
            catch (Exception e)
            {
                result.Success   = false;
                result.Message   = "Error rework document.";
                result.ErrorCode = ErrorCode.EXCEPTION;
                _logger.LogError("Error calling ReworkDocuments: {0}", e.Message);
            }
            return(result);
        }
Пример #6
0
        public ActionResult <Logs> Post([FromBody] LogsDTO log)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            Logs DtoToLog = _mapper.Map <Logs>(log);

            var result = logs.addLog(DtoToLog);

            if (result != null)
            {
                return(Ok(result));
            }
            else
            {
                return(NoContent());
            }
        }
Пример #7
0
        public async Task <Result> ApproveDocuments(List <string> ids, string userRole, string userId)
        {
            int    count  = 0;
            Result result = new Result();

            //approve each document. Add ID to respective approver
            foreach (string id in ids)
            {
                var wfi = await _repo.GetFirstAsync <WorkflowInbox>(
                    filter : (c => c.DocumentId == id));

                Document approvedDocument = await _repo.GetByIdAsync <Document>(Convert.ToInt32(id));

                try
                {
                    //if the approver is Department Head
                    if (userRole == nameof(Role.DEPTHEAD))
                    {
                        //after approving by Department Head, change the approver to higher authority which is DPO and ADMIN
                        wfi.ApproverRole = nameof(Role.DPO) + "," + nameof(Role.ADMINISTRATOR);
                        _repo.Update(wfi);
                        await _repo.SaveAsync();
                    }

                    //if the approver is DPO, or ADMINISTRATOR
                    else if (userRole == nameof(Role.DPO) || userRole == nameof(Role.ADMINISTRATOR))
                    {
                        //after approving by DPO or ADMIN, remove the item in inbox and change the status of the Document

                        //update status of approved Document

                        approvedDocument.State = State.Approved;
                        if (approvedDocument.RequestType == RequestType.Edit)
                        {
                            var fields = await _repo.GetAsync <DocumentField>(
                                filter : (c => c.DocumentId == Convert.ToInt32(wfi.DocumentId)));

                            var docField = fields.OrderBy(x => x.SubModuleId);

                            foreach (var field in docField)
                            {
                                if (field.IsEdited)
                                {
                                    field.Value    = field.NewValue;
                                    field.IsEdited = false;
                                    //TODO:insert to data history the change edited value
                                    field.NewValue = null;

                                    _repo.Update(field);
                                    await _repo.SaveAsync();
                                }
                                approvedDocument.Status = (Status)(field.SubModuleId - 1);
                            }
                        }

                        _repo.Update(approvedDocument);
                        await _repo.SaveAsync();

                        //removing item in inbox
                        _repo.Delete(wfi);
                        _repo.Save();
                    }
                    //Add to logs
                    LogsDTO dtoLogs = new LogsDTO();
                    dtoLogs.DocId       = approvedDocument.Id.ToString();;
                    dtoLogs.DataNumber  = approvedDocument.DataNumber;
                    dtoLogs.UserId      = userId;
                    dtoLogs.Action      = "Approve";
                    dtoLogs.Description = "Document approved by " + userRole;
                    var log = await _adminService.AddLogs(dtoLogs);

                    //count how many documents have been approved
                    count++;
                    result.Message = count.ToString() + " " + (count > 1 ? "documents" : "document") + " " + (count > 1 ? "have" : "has") + " been successfully approved.";
                    result.Success = true;
                }
                catch (Exception e)
                {
                    result.Success   = false;
                    result.Message   = "Error approving document.";
                    result.ErrorCode = ErrorCode.EXCEPTION;
                    _logger.LogError("Error calling ApproveDocuments: {0}", e.Message);
                }
            }

            return(result);
        }
Пример #8
0
        public void SetLog <S, T>(S entity, T model, Entity.Entities.MspDbContext db, int RecId)
        {
            string tableName      = entity.GetType().CustomAttributes.Count() == 0 ? entity.GetType().BaseType.Name : entity.GetType().Name;
            var    diffirences    = new LogsDTO();
            Type   entiType       = entity.GetType();
            Type   modelType      = model.GetType();
            var    tableId        = (dynamic)null;
            var    modelPropertys = modelType.GetProperties();
            var    properties     = entiType.GetProperties();

            foreach (var item in properties)
            {
                var targetProperty = modelType.GetProperty(item.Name);
                if (targetProperty != null && item.PropertyType.Equals(targetProperty.PropertyType))
                {
                    if (item.PropertyType.IsGenericType && !item.PropertyType.IsValueType)
                    {
                        continue;
                    }

                    object oldValue = item.GetValue(entity, null);
                    object newValue = item.GetValue(Map <T, S>(model), null);
                    if (oldValue == null && newValue == null)
                    {
                        continue;
                    }
                    if (oldValue != null && newValue != null)
                    {
                        if (oldValue.ToString().Length > 50)
                        {
                            oldValue = oldValue.ToString().Substring(0, 50);
                        }
                        if (newValue.ToString().Length > 50)
                        {
                            newValue = newValue.ToString().Substring(0, 50);
                        }
                    }


                    if (oldValue != null && newValue != null && !oldValue.Equals(newValue))
                    {
                        if (tableId == null)
                        {
                            for (int k = 0; k < properties.Length; k++)
                            {
                                if (properties[k].Name == "RecId")
                                {
                                    tableId = properties[k].GetValue(entity, null);
                                }
                            }
                        }
                        diffirences.UserCode     = AppMain.User.username;
                        diffirences.CompanyCode  = "";// Global.Company.CompanyCode;
                        diffirences.FieldName    = item.Name;
                        diffirences.TableName    = tableName;
                        diffirences.Old          = oldValue.ToString();
                        diffirences.New          = newValue.ToString();
                        diffirences.PCName       = Environment.MachineName.ToString();
                        diffirences.FormName     = "";                   //FormName;
                        diffirences.CompanyRecId = AppMain.CompanyRecId; // Global.Company.RecId;
                        db.LOGS.Add(Map <LogsDTO, Logs>(diffirences));
                    }
                }
            }
        }