Ejemplo n.º 1
0
        public async Task ReplayEvents(List <string> stream, Guid?entityId)
        {
            var messages = new List <Message>();

            foreach (var item in stream)
            {
                messages.Add(JsonConvert.DeserializeObject <Message>(item));
            }
            var replayOrderedStream = messages.OrderBy(d => d.Created);

            foreach (var msg in replayOrderedStream)
            {
                switch (msg.MessageType)
                {
                case MessageType.SoucastCreated:
                    break;

                case MessageType.SoucastRemoved:
                    break;

                case MessageType.SoucastUpdated:
                    break;

                case MessageType.UzivatelCreated:
                    break;

                case MessageType.UzivatelRemoved:
                    break;

                case MessageType.UzivatelUpdated:
                    break;
                }
            }
            await db.SaveChangesAsync();
        }
Ejemplo n.º 2
0
        public async Task <ActionResult <Ad> > DeleteAd(int id)
        {
            // Telemetry
            _tProperties["Action"] = "DeleteAd";

            try
            {
                var ad = await _context.tb_AnuncioWebmotors.FindAsync(id);

                if (ad == null)
                {
                    return(NotFound());
                }

                _context.tb_AnuncioWebmotors.Remove(ad);
                await _context.SaveChangesAsync();

                return(ad);
            }
            catch (Exception ex)
            {
                _telemetry.TrackException(ex, _tProperties);
                return(BadRequest(ex));
            }
        }
Ejemplo n.º 3
0
        public async Task ReplayEvents(List <string> stream, Guid?entityId)
        {
            var messages = new List <Message>();

            foreach (var item in stream)
            {
                messages.Add(JsonConvert.DeserializeObject <Message>(item));
            }
            var replayOrderedStream = messages.OrderBy(d => d.Created);

            foreach (var msg in replayOrderedStream)
            {
                //switch (msg.MessageType)
                //{
                //    case MessageType.UzivatelCreated:
                //        var create = JsonConvert.DeserializeObject<EventTransferCreated>(msg.Event);
                //        var forCreate = db.Transfers.FirstOrDefault(u => u.TransferId == create.TransferId);
                //        if (forCreate == null)
                //        {
                //            forCreate = Create(create);
                //            db.Transfers.Add(forCreate);
                //            db.SaveChanges();
                //        }

                //}
            }
            await db.SaveChangesAsync();
        }
        public TryAsync <CalendarEvent> CreateAsync(CalendarEvent entity) => async() =>
        {
            entity.CalendarEventMembers = await GetMembersAsync(entity);

            var created = _context.Add(entity);
            await _context.SaveChangesAsync();

            return(created.Entity);
        };
Ejemplo n.º 5
0
        public async Task Consume(ConsumeContext <FullOrgData> context)
        {
            //sort: department,position,employee
            var message = context.Message;

            if (message.Contacts == null ||
                message.Contacts.Count == 0 ||
                message.OrgUnits == null ||
                message.OrgUnits.Count == 0)
            {
                return;
            }

            if (!await this.EnsureHistoryChangedAsync(message.DataVersion, message.OrgUnits.Count, message.Contacts.Count))
            {
                return;
            }
            var departments       = this._mapper.Map <List <Department> >(message.OrgUnits);
            var positions         = departments.SelectMany(u => u.Positions).ToList();
            var employees         = this._mapper.Map <List <Employee> >(message.Contacts);
            var employeePositions = employees.SelectMany(u => u.Positions).ToList();

            employeePositions = this.RemoveRepeatAndNull(employeePositions);
            using (var db = new ServiceDbContext(_dbOptions))
            {
                try
                {
                    await this.FillInManualDataAsync(db, departments, positions, employees, employeePositions);

                    await db.BulkInsertOrUpdateOrDeleteAsync(departments);

                    await db.BulkInsertOrUpdateOrDeleteAsync(positions);

                    await db.BulkInsertOrUpdateOrDeleteAsync(employees);

                    await db.BulkInsertOrUpdateOrDeleteAsync(employeePositions);

                    await db.SaveChangesAsync();

                    await db.MdmDataHistories.AddAsync(new MdmDataHistory()
                    {
                        HistoryVersion = message.DataVersion,
                        SyncTime       = DateTimeOffset.Now,
                        Description    = $"Departments:{message.OrgUnits.Count},Employeees:{message.Contacts.Count}"
                    });

                    await db.SaveChangesAsync();
                }
                catch (Exception ex)
                {
                    ServiceEventSource.Current.Message(ex.ToString());
                }
            }
        }
Ejemplo n.º 6
0
        public bool addToStock(Domain.Models.Produto prod)
        {
            Produto[] data = db.Produtos.Where(x => x.Id > 0).ToArray();
            bool      res  = new ValidaNovoProduto().ValidaEntradasNaLista(data, prod.Codigo, prod.Nome);

            if (res is true)
            {
                db.Produtos.AddAsync(prod);
            }

            db.SaveChangesAsync();
            return(res);
        }
Ejemplo n.º 7
0
        public async Task ReplayEvents(List <string> stream, Guid?entityId)
        {
            var messages = new List <Message>();

            foreach (var item in stream)
            {
                messages.Add(JsonConvert.DeserializeObject <Message>(item));
            }
            var replayOrderedStream = messages.OrderBy(d => d.Created);

            foreach (var msg in replayOrderedStream)
            {
                switch (msg.MessageType)
                {
                case MessageType.DochazkaCreated:
                    var create    = JsonConvert.DeserializeObject <EventDochazkaCreated>(msg.Event);
                    var forCreate = db.Dochazka.FirstOrDefault(u => u.DochazkaId == create.DochazkaId);
                    if (forCreate == null)
                    {
                        forCreate = Create(create);
                        db.Dochazka.Add(forCreate);
                        db.SaveChanges();
                    }

                    break;

                case MessageType.DochazkaDeleted:
                    var remove    = JsonConvert.DeserializeObject <EventDochazkaDeleted>(msg.Event);
                    var forRemove = db.Dochazka.FirstOrDefault(u => u.DochazkaId == remove.DochazkaId);
                    if (forRemove != null)
                    {
                        db.Dochazka.Remove(forRemove);
                    }

                    break;

                case MessageType.DochazkaUpdated:
                    var update    = JsonConvert.DeserializeObject <EventDochazkaUpdated>(msg.Event);
                    var forUpdate = db.Dochazka.FirstOrDefault(u => u.DochazkaId == update.DochazkaId);
                    if (forUpdate != null)
                    {
                        forUpdate = Modify(update, forUpdate);
                        db.Dochazka.Update(forUpdate);
                        db.SaveChanges();
                    }
                    break;
                }
            }
            await db.SaveChangesAsync();
        }
        public async Task TestSearchByKeywordAsync()
        {
            var(connection, options) = OpenDb();

            try
            {
                var employess = new List <Employee>()
                {
                    new Employee
                    {
                        Id                  = Guid.NewGuid(),
                        Number              = "1",
                        IdCardNo            = "1",
                        Name                = "aaa",
                        PrimaryDepartmentId = Guid.NewGuid(),
                        PrimaryPositionId   = Guid.NewGuid(),
                    },
                    new Employee
                    {
                        Id                  = Guid.NewGuid(),
                        Number              = "2",
                        IdCardNo            = "2",
                        Name                = "aabb",
                        PrimaryDepartmentId = Guid.NewGuid(),
                        PrimaryPositionId   = Guid.NewGuid(),
                    },
                    new Employee
                    {
                        Id                  = Guid.NewGuid(),
                        Number              = "3",
                        IdCardNo            = "3",
                        Name                = "bbcc",
                        PrimaryDepartmentId = Guid.NewGuid(),
                        PrimaryPositionId   = Guid.NewGuid(),
                    },
                };

                using (var db = new ServiceDbContext(options))
                {
                    await db.Employees.AddRangeAsync(employess);

                    await db.SaveChangesAsync();
                }


                var target = new EmployeeAppService(statelessServiceContext, options, CreateMapper());

                var result = await target.SearchByKeywordAsync("aa");

                result.Count.Should().Be(2);

                result = await target.SearchByKeywordAsync("bb");

                result.Count.Should().Be(2);
            }
            finally
            {
                connection.Close();
            }
        }
Ejemplo n.º 9
0
        public async Task Consume(ConsumeContext <FullOrgData> context)
        {
            //sort: department,position,employee
            var message = context.Message;

            if (message.Contacts == null ||
                message.Contacts.Count == 0 ||
                message.OrgUnits == null ||
                message.OrgUnits.Count == 0)
            {
                return;
            }

            if (!await this.EnsureHistoryChangedAsync(message.DataVersion, message.OrgUnits.Count, message.Contacts.Count))
            {
                return;
            }
            var departments       = this._mapper.Map <List <Department> >(message.OrgUnits);
            var positions         = departments.SelectMany(u => u.Positions).ToList();
            var employees         = this._mapper.Map <List <Employee> >(message.Contacts);
            var employeePositions = employees.SelectMany(u => u.Positions).ToList();

            employeePositions = this.RemoveRepeatAndNull(employeePositions);
            using (var db = new ServiceDbContext(_dbOptions))
            {
                try
                {
                    await this.FillInManualDataAsync(db, departments, positions, employees, employeePositions);

                    await db.BulkInsertOrUpdateOrDeleteAsync(departments);

                    await db.BulkInsertOrUpdateOrDeleteAsync(positions);

                    await db.BulkInsertOrUpdateOrDeleteAsync(employees);

                    await db.BulkInsertOrUpdateOrDeleteAsync(employeePositions);

                    await db.SaveChangesAsync();

                    await db.SaveChangesAsync();
                }
                catch (Exception ex)
                {
                    throw;
                }
            }
        }
Ejemplo n.º 10
0
        public async Task TestCreateCustomAsync()
        {
            var(connection, options) = OpenDb();

            try
            {
                var emp1 = new Employee
                {
                    Id                  = Guid.NewGuid(),
                    UserId              = Guid.NewGuid(),
                    Number              = "1",
                    IdCardNo            = "1",
                    Name                = "aaa",
                    PrimaryDepartmentId = Guid.Empty,
                    PrimaryPositionId   = Guid.Empty,
                };
                var emp2 = new Employee
                {
                    Id                  = Guid.NewGuid(),
                    UserId              = Guid.NewGuid(),
                    Number              = "2",
                    IdCardNo            = "2",
                    Name                = "bbb",
                    PrimaryDepartmentId = Guid.Empty,
                    PrimaryPositionId   = Guid.Empty,
                };
                using (var db = new ServiceDbContext(options))
                {
                    await db.Employees.AddRangeAsync(emp1, emp2);

                    await db.SaveChangesAsync();
                }

                var bus = Substitute.For <IBusControl>();
                bus.Publish(Arg.Any <GroupAdded>())
                .Returns(Task.CompletedTask);

                var target = new GroupAppService(statelessServiceContext, options, CreateMapper(),
                                                 CreateMockSimpleKeyValueService(), bus);

                var result = await target.CreateCustomAsync(new GroupInput
                {
                    CurrentUserId     = emp1.UserId.Value,
                    CurrentEmployeeId = emp1.Id,
                    Name            = "aaa",
                    AddingMemberIds = new HashSet <Guid> {
                        emp1.Id, emp2.Id
                    }
                });

                result.Should().NotBe(Guid.Empty);

                await bus.Received(1).Publish(Arg.Is <GroupAdded>(x => x.Id == result));
            }
            finally
            {
                connection.Close();
            }
        }
Ejemplo n.º 11
0
        public async Task LastEventCheck(Guid eventId, Guid entityId)
        {
            var item = db.Aktivity.FirstOrDefault(u => u.AktivitaId == entityId);

            if (item != null)
            {
                if (item.EventGuid != eventId)
                {
                    await RequestEvents(entityId);
                }
                else
                {
                    item.Generation = item.Generation + 1;
                    await db.SaveChangesAsync();
                }
            }
        }
Ejemplo n.º 12
0
        /// <summary>
        /// 添加联系人
        /// </summary>
        /// <param name="adds"></param>
        /// <returns></returns>
        private async Task AddContacts(IList <ContactAddedMsg> adds)
        {
            var employees = this._mapper.Map <IList <Employee> >(adds.Select(u => u.NewData));

            using (var db = new ServiceDbContext(_dbOptions))
            {
                await db.BulkInsertAsync(employees);

                await db.SaveChangesAsync();
            }
        }
Ejemplo n.º 13
0
        /// <summary>
        /// 删除联系人,
        /// </summary>
        /// <param name="deletes"></param>
        /// <returns></returns>
        private async Task DeleteContacts(List <ContactDeletedMsg> deletes)
        {
            var employees = this._mapper.Map <IList <Employee> >(deletes.Select(u => u.OldData));

            using (var db = new ServiceDbContext(_dbOptions))
            {
                await db.BulkDeleteAsync(employees);

                await db.SaveChangesAsync();
            }
        }
Ejemplo n.º 14
0
        //Description: Ověření aktuálního stavu entity po uložení a publikaci
        public async Task LastEventCheck(Guid eventId, Guid entityId)
        {
            //Description: Nalezení záznamu
            var item = db.Uzivatele.FirstOrDefault(u => u.UzivatelId == entityId);

            if (item != null)
            {
                if (item.EventGuid != eventId)
                {
                    //Description: Pokud nesouhlasi ID události, vyžádej obnovu entity
                    await RequestEvents(entityId);
                }
                else
                {
                    //Description: Potvrzení úravy entity
                    item.Generation += 1;
                    await db.SaveChangesAsync();
                }
            }
        }
        public async Task Process(string jsonMessage)
        {
            var command = JsonConvert.DeserializeObject <MessageModelExample>(jsonMessage);

            var longRunningTask = _db.Tasks.Add(new LongRunningTask
            {
                Result             = "No result",
                RunningTimeSeconds = command.NewTaskTime,
                Status             = LongRunningTaskStatus.InProgress.ToString("G"),
                TaskName           = command.NewTaskName
            });

            await _db.SaveChangesAsync();

            await Task.Delay(TimeSpan.FromSeconds(command.NewTaskTime));

            longRunningTask.Entity.Result = $"Task '{longRunningTask.Entity.Id}'-'{longRunningTask.Entity.TaskName}' completed after '{longRunningTask.Entity.RunningTimeSeconds}' seconds.";
            longRunningTask.Entity.Status = LongRunningTaskStatus.Completed.ToString("G");

            await _db.SaveChangesAsync();
        }
Ejemplo n.º 16
0
        public async Task TestSearchByKeywordAsync()
        {
            var(connection, options) = OpenDb();

            try
            {
                var dep1 = new Department
                {
                    Id     = Guid.NewGuid(),
                    Number = "1",
                    Name   = "sclq"
                };
                var dep2 = new Department
                {
                    Id       = Guid.NewGuid(),
                    ParentId = dep1.Id,
                    Number   = "2",
                    Name     = "sclqgs"
                };
                var dep3 = new Department
                {
                    Id       = Guid.NewGuid(),
                    ParentId = dep1.Id,
                    Number   = "3",
                    Name     = "sclqjt"
                };

                using (var db = new ServiceDbContext(options))
                {
                    await db.Departments.AddRangeAsync(dep1, dep2, dep3);

                    await db.SaveChangesAsync();
                }


                var target = new DepartmentAppService(statelessServiceContext, options, CreateMapper());

                var result = await target.SearchByKeywordAsync("sclq");

                result.Count.Should().Be(3);

                result = await target.SearchByKeywordAsync("gs");

                result.Count.Should().Be(1);
            }
            finally
            {
                connection.Close();
            }
        }
        public async Task <ViewResult> SignUp(UserRegisterModel user)
        {
            if (ModelState.IsValid)
            {
                User newUser = new User {
                    Name = user.Name, Surname = user.Surname, BirthDate = user.BirthDate, Email = user.Email
                };
                await db.Users.AddAsync(newUser);

                await db.SaveChangesAsync();

                return(View("Thanks"));
            }
            return(View());
        }
Ejemplo n.º 18
0
        public async Task AddMessageAsync(string msg)
        {
            //Description: Deserializace události jako obecné zprávy a uložení do DB
            var origin  = JsonConvert.DeserializeObject <Message>(msg);
            var message = new StoreMessage
            {
                Guid            = Guid.NewGuid(),
                MessageType     = origin.MessageType,
                MessageTypeText = origin.MessageType.ToString(),
                Created         = origin.Created,
                EntityId        = origin.EntityId,
                Message         = msg
            };

            db.Messages.Add(message);
            await db.SaveChangesAsync();
        }
Ejemplo n.º 19
0
        public async Task TestDeleteAsync_Success()
        {
            var(connection, options) = OpenDb();

            try
            {
                var gp1 = new Group
                {
                    Id        = Guid.NewGuid(),
                    Name      = "aaa",
                    Type      = GroupType.CustomChat,
                    CreatedBy = Guid.NewGuid(),
                    Created   = DateTimeOffset.UtcNow,
                    Updated   = DateTimeOffset.UtcNow,
                };

                using (var db = new ServiceDbContext(options))
                {
                    await db.Groups.AddRangeAsync(gp1);

                    await db.SaveChangesAsync();
                }

                var target = new GroupAppService(statelessServiceContext, options, CreateMapper(),
                                                 CreateMockSimpleKeyValueService(), Substitute.For <IBusControl>());

                var result = await target.DeleteAsync(new GroupInput
                {
                    Id            = gp1.Id,
                    CurrentUserId = gp1.CreatedBy,
                });

                result.IsSuccess.Should().BeTrue();

                using (var db = new ServiceDbContext(options))
                {
                    var entity = await db.Groups.FindAsync(gp1.Id);

                    entity.Should().BeNull();
                }
            }
            finally
            {
                connection.Close();
            }
        }
        public async Task <IActionResult> AddAsync([FromBody] Number number)
        {
            int result = 0;

            if (ModelState.IsValid)
            {
                _logger.LogInformation((int)CalculateEnum.Add, "Request to Json", "Method started ");
                try
                {
                    _logger.LogInformation((int)CalculateEnum.Add, "Request to Soap", "Request sent");
                    result = await _soapClient.AddAsync(number.FirstNumber, number.SecondNumber);

                    _logger.LogInformation((int)CalculateEnum.Add, "Response from Soap", "Request success");

                    using (var transaction = await _dbContext.Database.BeginTransactionAsync())
                    {
                        Table table = new Table();
                        _dbContext.Tables.Add(table);
                        await _dbContext.SaveChangesAsync();

                        SecondTable second = new SecondTable
                        {
                            Value   = result.ToString(),
                            TableId = table.Id
                        };
                        await _dbContext.SecondTables.AddAsync(second);

                        await _dbContext.SaveChangesAsync();

                        await transaction.CommitAsync();
                    }
                }
                catch (Exception exp)
                {
                    _logger.LogError((int)CalculateEnum.Add, "Error message", exp.Message);
                    return(BadRequest(exp.Message));
                }
                return(Ok(result));
            }
            return(BadRequest(ModelState));
        }
Ejemplo n.º 21
0
 public async Task DeleteFileItemAsync(Guid fileId)
 {
     using (var db = new ServiceDbContext(_dbContextOptions))
     {
         try
         {
             var result = db.FileItems.FirstOrDefault(fi => fi.Id.Equals(fileId));
             if (result != null)
             {
                 db.FileItems.Remove(result);
                 await db.SaveChangesAsync();
             }
         }
         catch (Exception e)
         {
             ServiceEventSource.Current.Message("DeleteFileItemAsync try delete file:{0},but do not found!,exception:{1}", fileId, e.ToString());
         }
     }
 }
Ejemplo n.º 22
0
        public async Task TestGetListByIdsAsync()
        {
            var(connection, options) = OpenDb();

            try
            {
                var gp1 = new Group
                {
                    Id      = Guid.NewGuid(),
                    Name    = "aaa",
                    Type    = GroupType.CustomChat,
                    Created = DateTimeOffset.UtcNow,
                    Updated = DateTimeOffset.UtcNow,
                };
                var gp2 = new Group
                {
                    Id      = Guid.NewGuid(),
                    Name    = "bbb",
                    Type    = GroupType.CustomChat,
                    Created = DateTimeOffset.UtcNow,
                    Updated = DateTimeOffset.UtcNow,
                };
                using (var db = new ServiceDbContext(options))
                {
                    await db.Groups.AddRangeAsync(gp1, gp2);

                    await db.SaveChangesAsync();
                }

                var target = new GroupAppService(statelessServiceContext, options, CreateMapper(),
                                                 CreateMockSimpleKeyValueService(), Substitute.For <IBusControl>());

                var result = await target.GetListByIdsAsync(new List <Guid> {
                    gp1.Id, gp2.Id
                });

                result.Count.Should().Be(2);
            }
            finally
            {
                connection.Close();
            }
        }
Ejemplo n.º 23
0
        public async Task <FileItemDto> UploadFileAsync(UploadInput param, Guid uploaderId)
        {
            using (var db = new ServiceDbContext(_dbContextOptions))
            {
                var fileItem = new FileItem
                {
                    Id             = Guid.NewGuid(),
                    DownloadAmount = 0,
                    GroupId        = param.GroupId,
                    Name           = param.FileName,
                    StoreId        = param.StoreId,
                    UpdatedOn      = DateTimeOffset.UtcNow,
                    UploaderId     = uploaderId,
                };
                await db.FileItems.AddAsync(fileItem);

                await db.SaveChangesAsync();

                return(_mapper.Map <FileItemDto>(fileItem));
            }
        }
Ejemplo n.º 24
0
        public async Task <string> DownloadFileAsync(Guid fileId)
        {
            using (var db = new ServiceDbContext(_dbContextOptions))
            {
                try
                {
                    var result = db.FileItems.FirstOrDefault(fi => fi.Id.Equals(fileId));
                    if (result != null)
                    {
                        result.DownloadAmount++;
                        await db.SaveChangesAsync();

                        return(result.StoreId);
                    }
                }
                catch (Exception e)
                {
                    ServiceEventSource.Current.Message("DownloadFileAsync try download file:{0},but do not found!,exception:{1}", fileId, e.ToString());
                }
                return(null);
            }
        }
Ejemplo n.º 25
0
        public async Task TestQuitAsync_Failed_OwnerCannotQuit()
        {
            var(connection, options) = OpenDb();

            try
            {
                var emp1 = new Employee
                {
                    Id                  = Guid.NewGuid(),
                    UserId              = Guid.NewGuid(),
                    Number              = "1",
                    IdCardNo            = "1",
                    Name                = "aaa",
                    PrimaryDepartmentId = Guid.Empty,
                    PrimaryPositionId   = Guid.Empty,
                };
                var emp2 = new Employee
                {
                    Id                  = Guid.NewGuid(),
                    Number              = "2",
                    IdCardNo            = "2",
                    Name                = "bbb",
                    PrimaryDepartmentId = Guid.Empty,
                    PrimaryPositionId   = Guid.Empty,
                };
                var gp1 = new Group
                {
                    Id        = Guid.NewGuid(),
                    Name      = "aaa",
                    Type      = GroupType.CustomChat,
                    CreatedBy = emp1.UserId.Value,
                    Created   = DateTimeOffset.UtcNow,
                    Updated   = DateTimeOffset.UtcNow,
                    Members   = new List <GroupMember>
                    {
                        new GroupMember
                        {
                            EmployeeId = emp1.Id,
                            IsOwner    = true,
                            Joined     = DateTimeOffset.UtcNow,
                        },
                        new GroupMember
                        {
                            EmployeeId = emp2.Id,
                            IsOwner    = false,
                            Joined     = DateTimeOffset.UtcNow,
                        }
                    }
                };

                using (var db = new ServiceDbContext(options))
                {
                    await db.Employees.AddRangeAsync(emp1, emp2);

                    await db.Groups.AddRangeAsync(gp1);

                    await db.SaveChangesAsync();
                }

                var target = new GroupAppService(statelessServiceContext, options, CreateMapper(),
                                                 CreateMockSimpleKeyValueService(), Substitute.For <IBusControl>());

                var result = await target.QuitAsync(new GroupInput
                {
                    Id = gp1.Id,
                    CurrentEmployeeId = emp1.Id,
                });

                result.IsSuccess.Should().BeFalse();
            }
            finally
            {
                connection.Close();
            }
        }
Ejemplo n.º 26
0
        public async Task TestCheckSameWhiteListGroupAsync_TargetNotInGroup()
        {
            var(connection, options) = OpenDb();

            try
            {
                var emp1 = new Employee
                {
                    Id                  = Guid.NewGuid(),
                    UserId              = Guid.NewGuid(),
                    Number              = "1",
                    IdCardNo            = "1",
                    Name                = "aaa",
                    PrimaryDepartmentId = Guid.Empty,
                    PrimaryPositionId   = Guid.Empty,
                };
                var emp2 = new Employee
                {
                    Id                  = Guid.NewGuid(),
                    Number              = "2",
                    IdCardNo            = "2",
                    Name                = "bbb",
                    PrimaryDepartmentId = Guid.Empty,
                    PrimaryPositionId   = Guid.Empty,
                };
                var gp1 = new Group
                {
                    Id      = Guid.NewGuid(),
                    Name    = "cxo",
                    Type    = GroupType.WhiteListChat,
                    Created = DateTimeOffset.UtcNow,
                    Updated = DateTimeOffset.UtcNow,
                };
                gp1.Members = new List <GroupMember>
                {
                    new GroupMember
                    {
                        EmployeeId = emp1.Id,
                        GroupId    = gp1.Id,
                        Joined     = DateTimeOffset.UtcNow,
                    },
                    //new GroupMember
                    //{
                    //    EmployeeId = emp2.Id,
                    //    GroupId = gp1.Id,
                    //    Joined = DateTimeOffset.UtcNow,
                    //}
                };
                //var gp2 = new Group
                //{
                //    Id = Guid.NewGuid(),
                //    Name = "gm",
                //    Type = GroupType.WhiteListChat,
                //    Created = DateTimeOffset.UtcNow,
                //    Updated = DateTimeOffset.UtcNow,
                //};
                //gp2.Members = new List<GroupMember>
                //{
                //    new GroupMember
                //    {
                //        EmployeeId = emp1.Id,
                //        GroupId = gp2.Id,
                //        Joined = DateTimeOffset.UtcNow
                //    }
                //};
                using (var db = new ServiceDbContext(options))
                {
                    await db.Employees.AddRangeAsync(emp1, emp2);

                    await db.Groups.AddRangeAsync(gp1);

                    await db.SaveChangesAsync();
                }

                var target = new GroupAppService(statelessServiceContext, options, CreateMapper(),
                                                 CreateMockSimpleKeyValueService(), Substitute.For <IBusControl>());

                var result = await target.CheckSameWhiteListGroupAsync(emp1.UserId.Value, emp2.Id);

                result.Should().BeTrue();
            }
            finally
            {
                connection.Close();
            }
        }
Ejemplo n.º 27
0
        public async Task TestGetListByEmployeeIdAsync()
        {
            var(connection, options) = OpenDb();

            try
            {
                var emp1 = new Employee
                {
                    Id                  = Guid.NewGuid(),
                    UserId              = Guid.NewGuid(),
                    Number              = "1",
                    IdCardNo            = "1",
                    Name                = "aaa",
                    PrimaryDepartmentId = Guid.Empty,
                    PrimaryPositionId   = Guid.Empty,
                };
                var gp1 = new Group
                {
                    Id      = Guid.NewGuid(),
                    Name    = "aaa",
                    Type    = GroupType.CustomChat,
                    Created = DateTimeOffset.UtcNow,
                    Updated = DateTimeOffset.UtcNow,
                };
                gp1.Members = new List <GroupMember>
                {
                    new GroupMember
                    {
                        EmployeeId = emp1.Id,
                        GroupId    = gp1.Id,
                        Joined     = DateTimeOffset.UtcNow,
                    }
                };
                var gp2 = new Group
                {
                    Id      = Guid.NewGuid(),
                    Name    = "bbb",
                    Type    = GroupType.CustomChat,
                    Created = DateTimeOffset.UtcNow,
                    Updated = DateTimeOffset.UtcNow,
                };
                gp2.Members = new List <GroupMember>
                {
                    new GroupMember
                    {
                        EmployeeId = emp1.Id,
                        GroupId    = gp2.Id,
                        Joined     = DateTimeOffset.UtcNow
                    }
                };
                using (var db = new ServiceDbContext(options))
                {
                    await db.Employees.AddRangeAsync(emp1);

                    await db.Groups.AddRangeAsync(gp1, gp2);

                    await db.SaveChangesAsync();
                }

                var target = new GroupAppService(statelessServiceContext, options, CreateMapper(),
                                                 CreateMockSimpleKeyValueService(), Substitute.For <IBusControl>());

                var result = await target.GetListByEmployeeIdAsync(emp1.Id);

                result.Count.Should().Be(2);
            }
            finally
            {
                connection.Close();
            }
        }
Ejemplo n.º 28
0
        public async Task TestUpdateAsync_Success()
        {
            var(connection, options) = OpenDb();

            try
            {
                var emp1 = new Employee
                {
                    Id                  = Guid.NewGuid(),
                    UserId              = Guid.NewGuid(),
                    Number              = "1",
                    IdCardNo            = "1",
                    Name                = "aaa",
                    PrimaryDepartmentId = Guid.Empty,
                    PrimaryPositionId   = Guid.Empty,
                };
                var emp2 = new Employee
                {
                    Id                  = Guid.NewGuid(),
                    Number              = "2",
                    IdCardNo            = "2",
                    Name                = "bbb",
                    PrimaryDepartmentId = Guid.Empty,
                    PrimaryPositionId   = Guid.Empty,
                };
                var emp3 = new Employee
                {
                    Id                  = Guid.NewGuid(),
                    Number              = "3",
                    IdCardNo            = "3",
                    Name                = "ccc",
                    PrimaryDepartmentId = Guid.Empty,
                    PrimaryPositionId   = Guid.Empty,
                };
                var gp1 = new Group
                {
                    Id        = Guid.NewGuid(),
                    Name      = "aaa",
                    Type      = GroupType.CustomChat,
                    CreatedBy = emp1.UserId.Value,
                    Created   = DateTimeOffset.UtcNow,
                    Updated   = DateTimeOffset.UtcNow,
                    Members   = new List <GroupMember>
                    {
                        new GroupMember
                        {
                            EmployeeId = emp1.Id,
                            IsOwner    = true,
                            Joined     = DateTimeOffset.UtcNow,
                        },
                        new GroupMember
                        {
                            EmployeeId = emp2.Id,
                            IsOwner    = false,
                            Joined     = DateTimeOffset.UtcNow,
                        }
                    }
                };

                using (var db = new ServiceDbContext(options))
                {
                    await db.Employees.AddRangeAsync(emp1, emp2, emp3);

                    await db.Groups.AddRangeAsync(gp1);

                    await db.SaveChangesAsync();
                }

                var target = new GroupAppService(statelessServiceContext, options, CreateMapper(),
                                                 CreateMockSimpleKeyValueService(), Substitute.For <IBusControl>());

                var result = await target.UpdateAsync(new GroupInput
                {
                    Id                = gp1.Id,
                    Name              = "bbb",
                    Remark            = "ccc",
                    CurrentUserId     = emp1.UserId.Value,
                    CurrentEmployeeId = emp1.Id,
                    AddingMemberIds   = new HashSet <Guid> {
                        emp3.Id
                    },
                    RemovingMemberIds = new HashSet <Guid> {
                        emp2.Id
                    }
                });

                result.IsSuccess.Should().BeTrue();

                using (var db = new ServiceDbContext(options))
                {
                    var entity = await db.Groups
                                 .Include(o => o.Members)
                                 .FirstOrDefaultAsync(o => o.Id == gp1.Id);

                    entity.Name.Should().Be("bbb");
                    entity.Remark.Should().Be("ccc");
                    entity.Members.Count.Should().Be(2);
                    entity.Members.Exists(o => o.EmployeeId == emp3.Id).Should().BeTrue();
                    entity.Members.Exists(o => o.EmployeeId == emp2.Id).Should().BeFalse();
                }
            }
            finally
            {
                connection.Close();
            }
        }
Ejemplo n.º 29
0
 public Task <int> InsertAsync(Domain entity)
 {
     serviceDbContext.Domain.Add(entity);
     return(serviceDbContext.SaveChangesAsync());
 }
Ejemplo n.º 30
0
 public Task <int> InsertClusterNodeAsync(ClusterNode entity)
 {
     serviceDbContext.ClusterNode.Add(entity);
     return(serviceDbContext.SaveChangesAsync());
 }