コード例 #1
0
        private void MakeParticipationDiploma(ParticipantEntity participant, Image img)
        {
            var g = Graphics.FromImage(img);

            var drawFont  = new Font("Arial", 48);
            var drawBrush = new SolidBrush(Color.Black);

            var texts = new List <ImageTextModel>
            {
                new ImageTextModel(participant.User.FullName, 1400f, 1002f),
                new ImageTextModel(participant.School, 1100f, 1124f),
                new ImageTextModel(participant.SchoolCity, 1524f, 1244f),
                new ImageTextModel(participant.MentoringTeacher, 1706f, 1481f)
                {
                    Font = new Font("Arial", 35)
                }
            };

            foreach (var textModel in texts)
            {
                g.DrawString(textModel.Text, textModel.Font ?? drawFont, drawBrush, textModel.X, textModel.Y);
            }

            g.Flush(FlushIntention.Flush);
            g.Dispose();
        }
コード例 #2
0
ファイル: ParticipantService.cs プロジェクト: dbags/ChatRoom
        public async Task <Participant> DeleteAsync(int id, ApplicationUser user, Action <string, string> AddErrorMessage)
        {
            ParticipantEntity deletedEntity = await _repository.SingleOrDefaultAsync(p => p.ID == id);

            if (deletedEntity == null)
            {
                // Use Dto for catching by Controller
                throw new EntityNotFoundException <Participant, int>(id);
            }

            Chatroom chatroom = await _chatroomService.GetAsync(deletedEntity.ChatroomID);

            if (user == null)
            {
                AddErrorMessage?.Invoke("General", "Only Logged-in user can perform this operation");
                return(null);
            }

            // Participant can be deleted by the Owner of a Chatroom, or itself
            if (user.Id != chatroom.OwnerID && user.Id != deletedEntity.UserID)
            {
                AddErrorMessage?.Invoke("General", "Only Owner of a Chatroom or Participant itself can perform this operation!");
                return(null);
            }

            if (_repository.Remove(deletedEntity) != null)
            {
                await _context.SaveChangesAsync();
            }
            return(_mappingService.EntityToDto(deletedEntity));
        }
コード例 #3
0
ファイル: ParticipantService.cs プロジェクト: dbags/ChatRoom
        public async Task <Participant> CreateAsync(Participant dto, ApplicationUser user, Action <string, string> AddErrorMessage)
        {
            if (user == null)
            {
                AddErrorMessage?.Invoke("General", "Only Logged-in user can perform this operation");
                return(null);
            }

            ParticipantEntity entity   = _mappingService.DtoToEntity(dto);
            Chatroom          chatroom = await _chatroomService.GetAsync(entity.ChatroomID);

            if (user.Id != chatroom.OwnerID)
            {
                AddErrorMessage?.Invoke("General", "Only Owner of a Chatroom can add participants!");
                return(null);
            }

            ParticipantEntity createdEntity = await _repository.CreateAsync(entity);

            if (createdEntity != null)
            {
                await _context.SaveChangesAsync();
            }

            createdEntity = await _repository.GetCompleteAsync(createdEntity.ID);

            Participant created = _mappingService.EntityToDto(createdEntity);

            created.Deletable = true;
            return(created);
        }
コード例 #4
0
        private void MakePrizeDiploma(Image img, string prize, string category, ParticipantEntity participant)
        {
            var g = Graphics.FromImage(img);

            var drawFont  = new Font("Arial", 42);
            var drawBrush = new SolidBrush(Color.Black);

            var texts = new List <ImageTextModel>
            {
                new ImageTextModel(prize, 2066, 843),
                new ImageTextModel(participant.User.LastName + " " + participant.User.FirstName, 1800, 990),
                // {Font = new Font("Arial", 42)},
                new ImageTextModel(participant.School, 1100, 1100),
                new ImageTextModel(participant.SchoolCity, 1651, 1215),
                new ImageTextModel(category, 1842, 1432),
                new ImageTextModel(participant.MentoringTeacher, 1746, 1555)
                {
                    Font = new Font("Arial", 35)
                },
            };

            foreach (var textModel in texts)
            {
                g.DrawString(textModel.Text, textModel.Font ?? drawFont, drawBrush, textModel.X, textModel.Y);
            }

            g.Flush(FlushIntention.Flush);
            g.Dispose();
        }
コード例 #5
0
        public ServiceMessage Update(ParticipantEditDTO participantEditDTO)
        {
            string message;
            bool   success = true;

            string oldName     = participantEditDTO.Name;
            string sportName   = participantEditDTO.SportName;
            string countryName = participantEditDTO.CountryName;

            string newName = participantEditDTO.NewParticipantName;

            try
            {
                ParticipantEntity participantEntity = unitOfWork.Participants.Get(oldName, sportName, countryName);
                if (participantEntity != null)
                {
                    participantEntity.Name = newName;
                    unitOfWork.Commit();

                    message = "Edited participant";
                }
                else
                {
                    message = "Such participant was not found";
                    success = false;
                }
            }
            catch (Exception ex)
            {
                message = ExceptionMessageBuilder.BuildMessage(ex);
                success = false;
            }

            return(new ServiceMessage(message, success));
        }
コード例 #6
0
        private ParticipantEntity ParticipantFrom(IDictionary <string, string> record)
        {
            var participant = new ParticipantEntity
            {
                OldPlatformId    = record["Id"],
                PhoneNumber      = record["Phone number"],
                Grade            = int.Parse(record["Grade"]),
                City             = record["City"],
                County           = record["County"],
                Country          = record["Country"],
                School           = record["School name"],
                SchoolCounty     = record["School county"],
                SchoolCountry    = record["School country"],
                SchoolCity       = record["School city"],
                IdCardSeries     = record["Id card type"],
                IdCardNumber     = record["Id card number"],
                Cnp              = record["Cnp"],
                MentoringTeacher = record["Mentoring teacher first name"] + " " + record["Mentoring teacher last name"],
                User             = new User
                {
                    FirstName = record["First name [User]"],
                    LastName  = record["Last name [User]"],
                    UserName  = record["Email [User]"],
                    Email     = record["Email [User]"]
                },
            };

            return(participant);
        }
コード例 #7
0
ファイル: ParticipantService.cs プロジェクト: dbags/ChatRoom
        public async Task <IEnumerable <Participant> > CreateRangeAsync(ParticipantRange range, ApplicationUser user, Action <string, string> AddErrorMessage)
        {
            if (range.Users == null || range.Users.Count == 0)
            {
                return(null);
            }

            if (user == null)
            {
                AddErrorMessage?.Invoke("General", "Only Logged-in user can perform this operation");
                return(null);
            }

            Chatroom chatroom = await _chatroomService.GetAsync(range.ChatroomID);

            if (user.Id != chatroom.OwnerID)
            {
                AddErrorMessage?.Invoke("General", "Only Owner of a Chatroom can add participants!");
                return(null);
            }

            List <ParticipantEntity> participants = new List <ParticipantEntity>();

            foreach (UserShort u in range.Users)
            {
                ParticipantEntity temp = new ParticipantEntity
                {
                    ChatroomID = range.ChatroomID,
                    UserID     = u.UserID,
                    User       = new ApplicationUser {
                        Id = u.UserID, UserName = u.UserName
                    },
                };
                _context.Entry(temp.User).State = EntityState.Unchanged;
                participants.Add(temp);
            }

            IEnumerable <ParticipantEntity> created = await _repository.CreateRangeAsync(participants);

            if (created != null && created.Any())
            {
                await _context.SaveChangesAsync();
            }

            IEnumerable <Participant> result = _mappingService.EntitiesToDtos(created);

            foreach (Participant p in result)
            {
                p.Deletable = (p.UserID != user.Id);
            }

            return(result);
        }
コード例 #8
0
        //TODO
        //Create and Update have much same code

        public ServiceMessage Create(ParticipantBaseDTO participantBaseDTO)
        {
            string message;
            bool   success = true;

            string sportName       = participantBaseDTO.SportName;
            string countryName     = participantBaseDTO.CountryName;
            string participantName = participantBaseDTO.Name;

            try
            {
                SportEntity   sportEntity   = unitOfWork.Sports.Get(sportName);
                CountryEntity countryEntity = unitOfWork.Countries.Get(countryName);

                if (sportEntity != null && countryEntity != null)
                {
                    bool exists = unitOfWork.Participants.Exists(participantName, sportEntity.Id, countryEntity.Id);
                    if (!exists)
                    {
                        ParticipantEntity participantEntity = new ParticipantEntity
                        {
                            Name      = participantName,
                            CountryId = countryEntity.Id,
                            SportId   = sportEntity.Id
                        };

                        unitOfWork.Participants.Add(participantEntity);
                        unitOfWork.Commit();

                        message = "Created new participant";
                    }
                    else
                    {
                        message = "Such participant already exists";
                        success = false;
                    }
                }
                else
                {
                    message = "Such sport or country was not found";
                    success = false;
                }
            }
            catch (Exception ex)
            {
                message = ExceptionMessageBuilder.BuildMessage(ex);
                success = false;
            }

            return(new ServiceMessage(message, success));
        }
コード例 #9
0
        public static Participant ToBo(this ParticipantEntity bo)
        {
            if (bo == null)
            {
                return(null);
            }

            return(new Participant
            {
                IdPersonne = bo.PersonneId,
                IdCourse = bo.CourseId,
                dossard = bo.dossard,
                EstCompetiteur = bo.EstCompetiteur,
                EstOrganisateur = bo.EstOrganisateur,
                dateInscription = bo.dateInscription
            });
        }
コード例 #10
0
        private PdfDocument GetPrizeDiploma(PdfDocument srcPdf, string prize, string category,
                                            ParticipantEntity participant)
        {
            var newPdf = new PdfDocument();

            foreach (var srcPdfPage in srcPdf.Pages)
            {
                newPdf.AddPage(srcPdfPage);
            }

            var page        = newPdf.Pages[0];
            var gfx         = XGraphics.FromPdfPage(page);
            var defaultFont = new XFont("OpenSans", 12, XFontStyle.Regular);

            var texts = new List <ImageTextModel>
            {
                new(prize, 498, 200) { XFont = new XFont("OpenSans", 16, XFontStyle.Bold) },
コード例 #11
0
ファイル: ParticipantService.cs プロジェクト: dbags/ChatRoom
        public async Task <Participant> LeaveChatroomAsync(int chatroomID, ApplicationUser user, Action <string, string> AddErrorMessage)
        {
            ParticipantEntity participantEntity =
                await _repository.SingleOrDefaultAsync(p => p.ChatroomID == chatroomID && p.UserID == user.Id);

            if (participantEntity == null)
            {
                return(null);
            }

            ParticipantEntity deletedEntity = _repository.Remove(participantEntity);

            if (deletedEntity != null)
            {
                await _context.SaveChangesAsync();
            }
            return(_mappingService.EntityToDto(deletedEntity));
        }
コード例 #12
0
        public ServiceMessage Delete(ParticipantBaseDTO participantBaseDTO)
        {
            string message;
            bool   success = true;

            string sportName       = participantBaseDTO.SportName;
            string countryName     = participantBaseDTO.CountryName;
            string participantName = participantBaseDTO.Name;

            try
            {
                SportEntity   sportEntity   = unitOfWork.Sports.Get(sportName);
                CountryEntity countryEntity = unitOfWork.Countries.Get(countryName);

                if (sportEntity != null && countryEntity != null)
                {
                    ParticipantEntity participantEntity = unitOfWork.Participants.Get(participantName, sportEntity.Id, countryEntity.Id);
                    if (participantEntity != null)
                    {
                        unitOfWork.Participants.Remove(participantEntity);
                        unitOfWork.Commit();

                        message = "Deleted participant";
                    }
                    else
                    {
                        message = "Such participant doesn't exist";
                        success = false;
                    }
                }
                else
                {
                    message = "Such sport or country was not found";
                    success = false;
                }
            }
            catch (Exception ex)
            {
                message = ExceptionMessageBuilder.BuildMessage(ex);
                success = false;
            }

            return(new ServiceMessage(message, success));
        }
コード例 #13
0
        /// <summary>
        /// 保存流程数据
        /// </summary>
        /// <param name="flowEngine">流程</param>
        /// <param name="category">分类</param>
        /// <param name="owner">具体业务数据对应的PK</param>
        public void FlowSave(Eastday.WorkFlowEngine.FlowEngine flowEngine)
        {
            using (WorkFlowBLL workFlowBLL = new WorkFlowBLL())
            {
                workFlowBLL.DbContext = workFlowBLL.CreateDbContext(true);
                WorkFlowEntity workFlowEntity = workFlowBLL.Usp_Flow_ByOwner(flowEngine.Attachment.Owner);
                if (workFlowEntity == null)
                {
                    workFlowEntity = new WorkFlowEntity();
                }
                workFlowEntity.I_Owner = flowEngine.Attachment.Owner;
                workFlowEntity.I_State = (int)flowEngine.FlowState;
                workFlowEntity.I_Flag  = 1;

                //ParticipantEntity
                var aCurrent = flowEngine.GetCurrent();
                var steps    = from step in flowEngine.FlowSteps where !(step is StepEnd) select step;
                List <ParticipantEntity> participants = new List <ParticipantEntity>();
                foreach (var step in steps)
                {
                    foreach (var node in step.Nodes)
                    {
                        ParticipantEntity participantEntity = new ParticipantEntity();
                        participantEntity.I_Reference = node.Participant.Reference;
                        participantEntity.I_WorkFlow  = workFlowEntity.Id;
                        participantEntity.C_Step      = step.Identification;
                        participantEntity.C_Node      = node.Identification;
                        participantEntity.I_Auditer   = node.Conclusion.Auditer;
                        participantEntity.D_Audit     = node.Conclusion.AuditDate;
                        participantEntity.I_Bind      = node.Participant.Category;
                        participantEntity.I_Current   = step == aCurrent && node.AuditType == AuditType.UnAudit ? 1 : (int)node.Conclusion.AuditType;

                        participants.Add(participantEntity);
                    }
                }

                if (workFlowBLL.Usp_Flow_Insert(workFlowEntity, participants) > 0)
                {
                    workFlowBLL.DbContext.CommitTransaction();
                    this.Save(flowEngine);
                }
            }
        }
コード例 #14
0
        private void CreatePdfWithTexts(XImage img, string pdfPath, ParticipantEntity participant)
        {
            var pdfPage = new PdfPage {
                Width = img.PointWidth, Height = img.PointHeight
            };
            var document = new PdfDocument();

            document.AddPage(pdfPage);
            var gfx = XGraphics.FromPdfPage(pdfPage);

            gfx.DrawImage(img, 0, 0);

            var drawFont  = new XFont("Arial", 48);
            var drawBrush = new XSolidBrush(XColors.Black);

            var texts = new List <ImageTextModel>
            {
                new ImageTextModel(participant.User.FullName, 1400f, 1002f),
                new ImageTextModel(participant.School, 1100f, 1124f),
                new ImageTextModel(participant.SchoolCity, 1524f, 1244f),
                new ImageTextModel(participant.MentoringTeacher, 1706f, 1481f)
                {
                    Font = new Font("Arial", 35)
                }
            };

            foreach (var textModel in texts)
            {
                gfx.DrawString(textModel.Text,
                               textModel.Font == null ? drawFont : new XFont("Arial", textModel.Font.Size), drawBrush, textModel.X,
                               textModel.Y);
            }

            document.Save(pdfPath);
            gfx.Dispose();
            document.Dispose();
        }
コード例 #15
0
 private async Task <ParticipantEntity> AddParticipant(ParticipantEntity participant)
 {
     _participantsCache.Add(participant);
     return(await _participantsRepo.Add(participant));
 }
コード例 #16
0
 /// <summary>
 /// 修改参赛人员信息
 /// </summary>
 /// <param name="aEditParticipant">参赛人员实体</param>
 /// <returns></returns>
 public bool UpdateUser(ParticipantEntity aEditParticipant)
 {
     return(mobjParticipantDAL.Update(aEditParticipant));
 }
コード例 #17
0
 /// <summary>
 /// 添加一条参赛人员信息记录
 /// </summary>
 /// <param name="aAddParticipant">参赛人员实体</param>
 /// <returns></returns>
 public bool InsertParticipant(ParticipantEntity aAddParticipant)
 {
     return(mobjParticipantDAL.Insert(aAddParticipant));
 }
コード例 #18
0
ファイル: ParticipantService.cs プロジェクト: dbags/ChatRoom
        public async Task <Participant> GetAsync(int id)
        {
            ParticipantEntity entity = await _repository.GetCompleteAsync(id);

            return(_mappingService.EntityToDto(entity));
        }