public IActionResult DeleteUser(int?id)
        {
            User user = _context.Users.Find(id);

            if (user != null)
            {
                _context.Users.Remove(user);
                _context.SaveChanges();
            }
            return(RedirectToAction("UserTable", "Administration"));
        }
Exemplo n.º 2
0
 public bool addAdmin(User user) // đây
 {
     if (context.User.Add(user) != null)
     {
         user.Role = "ADMIN"; // role này là của Database role của token nó khác nữa
         context.SaveChanges();
         return(true);
     }
     ;
     return(false);
 }
        public void addOrganization(Organization organization)
        {
            context.Organization.Add(organization);
            UserOrganization userOrganization = new UserOrganization();

            userOrganization.MemberId            = organization.AdminId;
            userOrganization.StatusMember        = "MEMBER";
            userOrganization.OrganizationId      = organization.Id;
            userOrganization.CurrentOrganization = false;
            context.UserOrganization.Add(userOrganization);
            context.SaveChanges();
        }
Exemplo n.º 4
0
 private void FingerprintClient_OnTouch(FingerPrintClient client, iClockEventArg evt)
 {
     try {
         using (var context = new WorkflowContext()) {
             var entity = new Domain.Entities.Queue.FingerPrint();
             entity.AttState     = evt.AttState;
             entity.EnrolmentNo  = evt.EnrollNumber;
             entity.IP           = evt.IP;
             entity.MachineNo    = evt.MachineNo;
             entity.IsInvalid    = evt.IsInValid;
             entity.MachineDate  = evt.CreatedDate;
             entity.Port         = evt.Port;
             entity.Status       = "NOT_QUEUE";
             entity.VerifyMethod = evt.VerifyMethod;
             entity.WorkCode     = evt.WorkCode;
             context.FingerPrints.Add(entity);
             if (context.ChangeTracker.HasChanges())
             {
                 context.SaveChanges();
             }
             SendToRabbitMQ(MessageCommandEnum.PUSH, entity.Id.ToString());
         }
     } catch (Exception ex) {
         logger.Error(ex.Message, ex);
     }
 }
 public Checklist addTemplate(Checklist template)
 {
     template.TimeCreated = DateTime.UtcNow;
     _context.Checklist.Add(template);
     _context.SaveChanges();
     return(_context.Checklist.Where(t => t.TimeCreated.Equals(template.TimeCreated) && t.UserId.Equals(template.UserId)).FirstOrDefault());
 }
Exemplo n.º 6
0
 public void AddWorkflow(Workflow workflow)
 {
     using(var context = new WorkflowContext())
     {
         context.Workflows.Add(workflow);
         context.SaveChanges();
     }
 }
Exemplo n.º 7
0
 public void AddWorkflow(Workflow workflow)
 {
     using (var context = new WorkflowContext())
     {
         context.Workflows.Add(workflow);
         context.SaveChanges();
     }
 }
Exemplo n.º 8
0
 public T SaveCommit(T entity)
 {
     using (var dbContext = new WorkflowContext())
     {
         var repository = dbContext.Set <T>();
         repository.Add(entity);
         dbContext.SaveChanges();
     }
     return(entity);
 }
Exemplo n.º 9
0
 public T Update(T entity)
 {
     using (var dbContext = new WorkflowContext())
     {
         var repository = dbContext.Set <T>();
         repository.Attach(entity);
         dbContext.Entry(entity).State = EntityState.Modified;
         dbContext.SaveChanges();
     }
     return(entity);
 }
Exemplo n.º 10
0
        private void LogTracks(int workflowRunId, CustomTrackingParticipant tracker)
        {
            var tracks = MapTracks(tracker.Records, (t) =>
            {
                t.WorkflowRunId = workflowRunId;
                return(t);
            });

            using (WorkflowContext context = new WorkflowContext())
            {
                context.Tracks.AddRange(tracks);
                context.SaveChanges();
            }
        }
        public void inviteMember(int organizationId, string email)
        {
            var listMember = getMemberByOrganizationId(organizationId);

            if (listMember.Where(m => m.Email.Equals(email) && m.Type.Equals("Google")).FirstOrDefault() == null)
            {
                var user             = context.User.Where(u => u.Email.Equals(email) && u.Type.Equals("Google")).FirstOrDefault();
                var userOrganization = new UserOrganization();
                userOrganization.CurrentOrganization = false;
                userOrganization.MemberId            = user.Id;
                userOrganization.StatusMember        = "WAITING";
                userOrganization.OrganizationId      = organizationId;
                context.UserOrganization.Add(userOrganization);
                context.SaveChanges();
            }
        }
Exemplo n.º 12
0
 public void UpdateFingerPrintStatus(string status)
 {
     using (var dbContext = new WorkflowContext()) {
         var fingerPrintMachine = dbContext.FingerPrintMachines.FirstOrDefault(p => p.IP == IP);
         if (fingerPrintMachine != null)
         {
             fingerPrintMachine.LastConnectedDate = DateTime.Now;
             fingerPrintMachine.Status            = status;
             dbContext.FingerPrintMachines.Attach(fingerPrintMachine);
             dbContext.Entry(fingerPrintMachine).State = EntityState.Modified;
             if (dbContext.ChangeTracker.HasChanges())
             {
                 dbContext.SaveChanges();
             }
         }
     }
 }
Exemplo n.º 13
0
 public IActionResult DataChange(User user, string newPassword, string confirmPassword)
 {
     if (newPassword == null || confirmPassword == null)
     {
         _context.Entry(user).State = EntityState.Modified;
         _context.SaveChanges();
         return(RedirectToAction("Index", "Home"));
     }
     else if (newPassword == confirmPassword && newPassword != null && confirmPassword != null)
     {
         user.UPassword             = MD5Hash(newPassword);
         _context.Entry(user).State = EntityState.Modified;
         _context.SaveChanges();
     }
     return(RedirectToAction("DataChange", "Home"));
 }
Exemplo n.º 14
0
        public static void Initialize(WorkflowContext context)
        {
            //context.Database.EnsureCreated();

            if (context.Campanhas.Any())
            {
                return;
            }

            Guid campanhaId = Guid.NewGuid();
            Guid workflowId = Guid.NewGuid();
            Guid templateId = Guid.NewGuid();

            var campanha = new CampanhaWorkflow()
            {
                CampanhaId  = campanhaId,
                DataCriacao = DateTime.Now,
                DataInicio  = DateTime.Now,
                Nome        = "Campanha de Teste",
                Publico     = 100,
                Status      = (int)WorkflowStatus.Ready,
                TemplateId  = templateId
            };

            context.Campanhas.AddRange(campanha);

            if (context.Workflow.Any())
            {
                return;
            }

            var workflow = new Workflow()
            {
                CampanhaId = campanhaId,
                Publico    = 100,
                Status     = (int)WorkflowStatus.Ready,
                TemplateId = templateId,
                WorkflowId = workflowId
            };

            context.Workflow.AddRange(workflow);
            context.SaveChanges();
        }
Exemplo n.º 15
0
 private void IClockClient_OnConnected()
 {
     logger.Info("IClockClient_OnConnected");
     IsConnected = true;
     using (var dbContext = new WorkflowContext()) {
         var fingerPrintMachine = dbContext.FingerPrintMachines.FirstOrDefault(p => p.IP == IP);
         if (fingerPrintMachine != null)
         {
             fingerPrintMachine.ConnectedDate = DateTime.Now;
             fingerPrintMachine.Status        = STATUS_CONNECTED;
             dbContext.FingerPrintMachines.Attach(fingerPrintMachine);
             dbContext.Entry(fingerPrintMachine).State = EntityState.Modified;
             if (dbContext.ChangeTracker.HasChanges())
             {
                 dbContext.SaveChanges();
             }
         }
     }
 }
Exemplo n.º 16
0
        public void addNewTaskItem(TaskItemViewModel taskItem)
        {
            var task = new TaskItem();

            task.ChecklistId = taskItem.ChecklistId;
            //  task.FormId = taskItem.FormId;
            task.DueTime = DateTime.ParseExact(taskItem.DueTime, "dd/MM/yyyy HH:mm:ss", CultureInfo.InvariantCulture);
            //task.DueTime = Convert.ToDateTime(taskItem.DueTime);

            task.Name       = taskItem.Name;
            task.Priority   = taskItem.Priority;
            task.TaskStatus = taskItem.TaskStatus;
            // task.FormSubmitted = taskItem.FormSubmitted;
            // task.FormId = taskItem.FormId;
            context.TaskItem.Add(task);
            context.SaveChanges();
        }
 public TEntity Save(TEntity entity)
 {
     DbSet.Add(entity);
     Db.SaveChanges();
     return(entity);
 }
Exemplo n.º 18
0
        public IList <TrackingRecord> StartWorkflow(int id, Dictionary <string, object> wfParams)
        {
            string fileLocation  = null;
            int    workflowRunId = 0;

            using (var context = new WorkflowContext())
            {
                fileLocation = context.Workflows.First(c => c.Id == id).FileLocation; // Hier kan een NullReferenceException optreden
                var workflowRun = new WorkflowRun()
                {
                    WorkflowId = id,
                    StartTime  = DateTime.Now
                };
                context.WorkflowRuns.Add(workflowRun);
                context.SaveChanges();
                workflowRunId = workflowRun.WorkflowRunId;
            }

            var xamlData = ReadXamlFile(fileLocation);

            var tracker = new CustomTrackingParticipant();
            var wf      = ActivityXamlServices.Load(new StringReader(xamlData), new ActivityXamlServicesSettings {
                CompileExpressions = true
            });

            AutoResetEvent      syncEvent = new AutoResetEvent(false);
            WorkflowApplication wfApp     = new WorkflowApplication(wf, wfParams);

            wfApp.Extensions.Add(tracker);
            wfApp.Extensions.Add <TextWriter>(() => new StreamWriter(@"C:/XAML/log.txt"));
            // Handle the desired lifecycle events.
            Exception exception = null;

            wfApp.Completed             = (e) => syncEvent.Set();
            wfApp.OnUnhandledException += (WorkflowApplicationUnhandledExceptionEventArgs e) =>
            {
                using (WorkflowContext context = new WorkflowContext())
                {
                    context.Tracks.Add(new Track()
                    {
                        ActivityName  = e.UnhandledException.ToString(),
                        EventTime     = DateTime.Now.AddHours(-1),
                        State         = "Faulted",
                        WorkflowRunId = workflowRunId,
                    });
                    context.SaveChanges();
                }
                LogTracks(workflowRunId, tracker);

                return(UnhandledExceptionAction.Terminate);
            };


            // Start the workflow.
            wfApp.Run();
            syncEvent.WaitOne();

            LogTracks(workflowRunId, tracker);

            return(tracker.Records);
        }
Exemplo n.º 19
0
        public IList<TrackingRecord> StartWorkflow(int id, Dictionary<string, object> wfParams)
        {
            string fileLocation = null;
            int workflowRunId = 0;
            using (var context = new WorkflowContext())
            {
                fileLocation = context.Workflows.First(c => c.Id == id).FileLocation; // Hier kan een NullReferenceException optreden
                var workflowRun = new WorkflowRun()
                {
                    WorkflowId = id,
                    StartTime = DateTime.Now
                };
                context.WorkflowRuns.Add(workflowRun);
                context.SaveChanges();
                workflowRunId = workflowRun.WorkflowRunId;
            }

            var xamlData = ReadXamlFile(fileLocation);

            var tracker = new CustomTrackingParticipant();
            var wf = ActivityXamlServices.Load(new StringReader(xamlData), new ActivityXamlServicesSettings {  CompileExpressions = true });

            AutoResetEvent syncEvent = new AutoResetEvent(false);
            WorkflowApplication wfApp = new WorkflowApplication(wf, wfParams);
            wfApp.Extensions.Add(tracker);
            wfApp.Extensions.Add<TextWriter>(() => new StreamWriter(@"C:/XAML/log.txt"));
            // Handle the desired lifecycle events.
            Exception exception = null;

            wfApp.Completed = (e) => syncEvent.Set();
            wfApp.OnUnhandledException += (WorkflowApplicationUnhandledExceptionEventArgs e) =>
            {
                using (WorkflowContext context = new WorkflowContext())
                {
                    context.Tracks.Add(new Track()
                    {
                        ActivityName = e.UnhandledException.ToString(),
                        EventTime = DateTime.Now.AddHours(-1),
                        State = "Faulted",
                        WorkflowRunId = workflowRunId,
                    });
                    context.SaveChanges();
                }
                LogTracks(workflowRunId, tracker);

                return UnhandledExceptionAction.Terminate;
            };

            // Start the workflow.
            wfApp.Run();
            syncEvent.WaitOne();

            LogTracks(workflowRunId, tracker);

            return tracker.Records;
        }
Exemplo n.º 20
0
        private void LogTracks(int workflowRunId, CustomTrackingParticipant tracker)
        {
            var tracks = MapTracks(tracker.Records, (t) =>
            {
                t.WorkflowRunId = workflowRunId;
                return t;
            });

            using (WorkflowContext context = new WorkflowContext())
            {
                context.Tracks.AddRange(tracks);
                context.SaveChanges();
            }
        }
Exemplo n.º 21
0
        /// <summary>
        /// Save email's data into database
        /// </summary>
        /// <param name="item">The email message item</param>
        /// <returns>The email item</returns>
        protected EmailItem SaveEmail(EmailMessage item)
        {
            if (item == null)
            {
                return(null);
            }
            using (var context = new WorkflowContext()) {
                if (context.Database.SqlQuery <int>(string.Format("SELECT TOP 1 1 FROM EMAIL.MAIL_ITEM WHERE UNIQUE_IDENTIFIER = '{0}' COLLATE Latin1_General_CS_AS ", item.Id.UniqueId)).Count() == 0)
                {
                    var emailitem = new EmailItem();
                    emailitem.Body             = InlineImageUtil.GetHTMLWithInlineImage(item);
                    emailitem.Cc               = GetEmailName(item.CcRecipients);
                    emailitem.Originator       = item.From.Address;
                    emailitem.Subject          = string.IsNullOrEmpty(item.Subject) ? "No Subject" : item.Subject;
                    emailitem.UniqueIdentifier = item.Id.UniqueId;
                    emailitem.Status           = EMAIL_STATUS;
                    emailitem.CreatedDate      = DateTime.Now;
                    emailitem.Receipient       = GetEmailName(item.ToRecipients);
                    emailitem.FileAttachements = new List <FileAttachement>();

                    if (item.HasAttachments)
                    {
                        foreach (var att in item.Attachments)
                        {
                            att.Load();

                            if (att.IsInline)
                            {
                                continue;
                            }

                            FileAttachment fileAtt = att as FileAttachment;
                            if (fileAtt != null)
                            {
                                MemoryStream memoryStream    = new MemoryStream();
                                var          fileAttachement = new FileAttachement();
                                fileAttachement.FileName    = att.Name;
                                fileAttachement.Ext         = Path.GetExtension(att.Name).Replace(".", "");
                                fileAttachement.CreatedDate = DateTime.Now;
                                fileAtt.Load(memoryStream);
                                fileAttachement.DataContent = memoryStream != null?memoryStream.ToArray() : null;

                                emailitem.FileAttachements.Add(fileAttachement);
                            }
                        }
                    }

                    if (emailitem.FileAttachements.Count == 0)
                    {
                        emailitem.FileAttachements = null;
                    }

                    context.EmailItems.Add(emailitem);

                    if (context.ChangeTracker.HasChanges())
                    {
                        context.SaveChanges();
                    }
                    _Logger.Info(emailitem);

                    return(emailitem);
                }
            }

            item.IsRead = true;
            item.Update(ConflictResolutionMode.AlwaysOverwrite);

            return(null);
        }