Пример #1
0
        public async Task RemoveUser(User user)
        {
            try
            {
                var dialog = new QuestionDialog("Do you want to remove this user (" + user.LongName + ")?");
                dialog.ShowDialog();
                if (dialog.DialogResult.HasValue && dialog.DialogResult.Value)
                {
                    using (var context = new NeoTrackerContext())
                    {
                        if (HeadOfDepartment != null && HeadOfDepartment.UserID == user.UserID)
                        {
                            HeadOfDepartment = null;
                            context.Entry(GetModel()).State = EntityState.Modified;
                            await context.SaveChangesAsync();
                        }
                        var data = await context.DepartmentUsers.FirstOrDefaultAsync(x => x.UserID == user.UserID && x.DepartmentID == DepartmentID);

                        if (data != null)
                        {
                            context.Entry(data).State = EntityState.Deleted;
                            await context.SaveChangesAsync();
                            await LoadUsers();
                        }
                    }
                }
                ;
            }
            catch (Exception e)
            {
                App.vm.UserMsg = e.Message.ToString();
            }
        }
        public async Task Delete()
        {
            try
            {
                var dialog = new QuestionDialog("Do you really want to delete this operation (" + Name + ")?");
                dialog.ShowDialog();
                if (dialog.DialogResult.HasValue && dialog.DialogResult.Value)
                {
                    using (var context = new NeoTrackerContext())
                    {
                        var data = GetModel();
                        context.Entry(data).State = EntityState.Deleted;
                        App.vm.Item.Operations.Remove(this);

                        var changeLogs = App.vm.ChangeLog.Where(x => x.EntityName == "Operation" && x.PrimaryKeyValue == data.OperationID).ToList();
                        changeLogs.ForEach(x => context.Entry(x).State = EntityState.Deleted);

                        await context.SaveChangesAsync();

                        EndEdit();
                    }
                }
            }
            catch (Exception e)
            {
                App.vm.UserMsg = e.Message.ToString();
            }
        }
Пример #3
0
        public async Task Save()
        {
            try
            {
                using (var context = new NeoTrackerContext())
                {
                    var data = GetModel();
                    if (EventID == 0)
                    {
                        context.Events.Add(data);
                    }
                    else
                    {
                        context.Entry(data).State = EntityState.Modified;
                    }
                    await context.SaveChangesAsync();
                }
                await App.vm.Project.LoadEvents();

                EndEdit();
            }
            catch (Exception e)
            {
                App.vm.UserMsg = e.Message.ToString();
            }
        }
Пример #4
0
        public async Task Delete()
        {
            try
            {
                var dialog = new QuestionDialog("Do you really want to delete this Event (" + Description + ")?");
                dialog.ShowDialog();
                if (dialog.DialogResult.HasValue && dialog.DialogResult.Value)
                {
                    using (var context = new NeoTrackerContext())
                    {
                        //if (CanDelete)
                        //{
                        var data = GetModel();
                        context.Entry(data).State = EntityState.Deleted;
                        App.vm.Project.Events.Remove(this);
                        await context.SaveChangesAsync();

                        EndEdit();
                        //}
                    }
                }
            }
            catch (Exception e)
            {
                App.vm.UserMsg = e.Message.ToString();
            }
        }
Пример #5
0
        public async Task RemoveDepartment(DepartmentViewModel department)
        {
            try
            {
                var dialog = new QuestionDialog("Do you want to remove this department (" + department.Name + ")?");
                dialog.ShowDialog();
                if (dialog.DialogResult.HasValue && dialog.DialogResult.Value)
                {
                    using (var context = new NeoTrackerContext())
                    {
                        var data = await context.DepartmentUsers.FirstOrDefaultAsync(x => x.DepartmentID == department.DepartmentID && x.UserID == UserID);

                        if (data != null)
                        {
                            context.Entry(data).State = EntityState.Deleted;
                            await context.SaveChangesAsync();
                            await LoadDepartments();
                        }
                    }
                }
                ;
            }
            catch (Exception e)
            {
                App.vm.UserMsg = e.Message.ToString();
            }
        }
Пример #6
0
 public async Task MassUpdateOperations(List <Operation> ops, DateTime?StartDate, DateTime?EndDate, bool?Completed)
 {
     if (ItemID != 0 && Operations.Any())
     {
         using (var context = new NeoTrackerContext())
         {
             foreach (var o in ops)
             {
                 if (EndDate.HasValue)
                 {
                     o.EndDate = EndDate.Value;
                 }
                 if (Completed.HasValue && Completed.Value)
                 {
                     o.IsCompleted = true;
                 }
                 if (StartDate.HasValue)
                 {
                     o.StartDate = StartDate.Value;
                 }
                 context.Entry(o).State = EntityState.Modified;
             }
             await context.SaveChangesAsync();
         }
     }
 }
Пример #7
0
        public async Task Save()
        {
            try
            {
                using (var context = new NeoTrackerContext())
                {
                    var data = GetModel();

                    context.Entry(data).State = EntityState.Modified;
                    await context.SaveChangesAsync();
                }
                EndEdit();
                await App.vm.LoadProjects();
            }
            catch (Exception e)
            {
                App.vm.UserMsg = e.Message.ToString();
            }
        }