Esempio n. 1
0
        /// <summary>
        /// Adds people to the database
        /// </summary>
        /// <param name="peopleEntity">People information</param>
        public void Operation(PeopleEntity peopleEntity)
        {
            if (string.IsNullOrEmpty(peopleEntity.Address))
            {
                throw new Exception("Address is null");
            }

            _databaseGood.Persist(peopleEntity);
        }
Esempio n. 2
0
        public PeopleViewModel GetPeople(Guid id)
        {
            PeopleEntity people = _dataBase.People.Find(id);

            return(new PeopleViewModel
            {
                Id = people.Id,
                BirthDate = people.BirthDate,
                Name = people.Name
            });
        }
Esempio n. 3
0
 /// <summary>
 /// 保存表单(新增、修改)
 /// </summary>
 /// <param name="keyValue">主键值</param>
 /// <param name="entity">实体对象</param>
 /// <returns></returns>
 public void SaveForm(string keyValue, PeopleEntity entity)
 {
     try
     {
         service.SaveForm(keyValue, entity);
     }
     catch (Exception)
     {
         throw;
     }
 }
Esempio n. 4
0
        public void AddPeople(PeopleViewModel people)
        {
            PeopleEntity newPeople = new PeopleEntity
            {
                Id        = people.Id,
                BirthDate = new DateTime(1992, 03, 26),
                Name      = "Lucas Ferla Gomes"
            };

            _dataBase.Add(newPeople);
            _dataBase.SaveChanges();
        }
        public async Task <ActionResult> Update([FromBody] PeopleEntity people)
        {
            try
            {
                _repository.Update(people);
                await _repository.SaveChangesAsync();

                return(Ok($"Объект c {people.Id} обновлен"));
            }
            catch (Exception exception)
            {
                return(BadRequest(exception.Message));
            }
        }
Esempio n. 6
0
        public PeopleEntity AddPerson(int companyId, PeopleEntity entity)
        {
            var  community = Storage.Instance.People[companyId];
            long max       = 0;

            if (community.Any())
            {
                max = community.Max(x => x.Id);
            }
            entity.Id = ++max;
            community.Add(entity);

            return(entity);
        }
Esempio n. 7
0
        protected virtual async Task <(PeopleEntity person, UsersEntity user, UsersProvidersEntity provider)> CastNewUser(SignUpEntity signUp)
        {
            var person = new PeopleEntity
            {
                Action       = EntityAction.New,
                IdPerson     = Guid.NewGuid(),
                Name         = signUp.Name,
                Email        = signUp.Email,
                Birthday     = signUp.BirthDay,
                Culture      = signUp.Language,
                Gender       = signUp.Male ? GenderType.Male : GenderType.Female,
                CreatedAt    = DateTime.Now,
                ChangedAt    = DateTime.Now,
                ImageCover   = signUp.UrlCover,
                ImageProfile = signUp.UrlImage
            };

            var user = new UsersEntity
            {
                Action            = EntityAction.New,
                IdUser            = person.IdPerson,
                IdPerson          = person.IdPerson,
                AccessFailedCount = 0,
                EmailConfirmed    = false,
                LockoutEnabled    = false,
                PasswordHash      = string.Empty,
                PhoneConfirmed    = false,
                ProfileComplete   = false
            };

            if (signUp.Provider == ProviderType.Local)
            {
                user.PasswordHash = await GetPasswordHashAsync(user, signUp.Password);
            }

            var userProvider = new UsersProvidersEntity
            {
                Action           = EntityAction.New,
                IdUserProvide    = Guid.NewGuid(),
                IdUser           = person.IdPerson,
                Provider         = signUp.Provider,
                ProviderDefault  = true,
                ProviderToken    = signUp.Token,
                ProviderUrlCover = signUp.UrlCover,
                ProviderUrlImage = signUp.UrlImage
            };

            return(await Task.FromResult((person, user, userProvider)));
        }
        public async Task <ActionResult> Create([FromBody] PeopleEntity people)
        {
            try
            {
                await _repository.CreateAsync(people);

                await _repository.SaveChangesAsync();

                return(Ok($"Объект с {people.Id} создан"));
            }
            catch (Exception exception)
            {
                return(BadRequest(exception.Message));
            }
        }
Esempio n. 9
0
        public static void RunExampleDip()
        {
            var peopleEntity = new PeopleEntity
            {
                Name    = "John Henao",
                Address = "Calle 31"
            };

            // Bad
            new Logic().Operation(peopleEntity);

            // Good
            //var provider = new FactoryDatabaseProvider(DatabaseProvider.SqlDatabase).GetProvider();
            //new LogicGood(provider).Operation(peopleEntity);

            Console.ReadLine();
        }
Esempio n. 10
0
 /// <summary>
 /// View documentation of <see cref="IDatabaseGood.Persist(PeopleEntity)"/> interface
 /// </summary>
 public void Persist(PeopleEntity peopleEntity)
 {
     Console.WriteLine($"Data for: {peopleEntity.Name} - saved in MongoDatabase Good");
 }
Esempio n. 11
0
        private ReportEntity BuildReport(PeopleEntity user, DateTime start, DateTime end, string reporttype)
        {
            var db = new RepositoryFactory().BaseRepository();

            var reportcontent = string.Empty;
            var tasks         = string.Empty;
            var undo          = string.Empty;
            var groupjobs     = default(List <TaskEntity>);

            if (reporttype == "月工作总结")
            {
                //月总结

                if (user.Quarters == "班长" || user.Quarters == "副班长" || user.Quarters == "技术员")
                {
                    //工作
                    var part1 = string.Empty;
                    var jobs  = (from q in db.IQueryable <MeetingJobEntity>()
                                 join q1 in db.IQueryable <MeetingAndJobEntity>() on q.JobId equals q1.JobId
                                 where q.GroupId == user.BZID && q.IsFinished != "cancel" && q.EndTime >= start && q.StartTime <= end && !string.IsNullOrEmpty(q1.StartMeetingId)
                                 select q).ToList();

                    if (jobs.Count > 0)
                    {
                        part1 = string.Format("本月安排工作任务{0}项,完成{1}项,{2}进行中,{3}未完成。", jobs.Count, jobs.Count(x => x.IsFinished == "finish"), jobs.Count(x => (x.IsFinished == "undo" || string.IsNullOrEmpty(x.IsFinished)) && x.EndTime > end), jobs.Count(x => (x.IsFinished == "undo" || string.IsNullOrEmpty(x.IsFinished)) && x.EndTime <= end));
                    }

                    //危险预知训练
                    var part2   = string.Empty;
                    var dangers = (from q in db.IQueryable <DangerEntity>()
                                   where q.GroupId == user.BZID && q.Status == 2 && q.JobTime >= start && q.JobTime <= end
                                   select q).ToList();
                    if (dangers.Count > 0)
                    {
                        part2 = string.Format("本月进行危险预知训练{0}", dangers.Count);
                    }

                    //班组活动
                    var part3      = string.Empty;
                    var activities = (from q in db.IQueryable <ActivityEntity>()
                                      where q.GroupId == user.BZID && q.State == "Finish" && q.StartTime >= start && q.StartTime <= end
                                      select q).ToList();
                    if (activities.Count > 0)
                    {
                        part3 = string.Format("本月进行了{0}", string.Join(",", activities.GroupBy(x => x.ActivityType).Select(x => string.Format("{0}次{1}", x.Count(), x.Key))));
                    }

                    //技术问答和事故预想
                    var part4 = string.Empty;
                    var acts  = (from q in db.IQueryable <EduBaseInfoEntity>()
                                 where q.BZId == user.BZID && q.Flow == "1" && q.StartDate >= start && q.StartDate <= end
                                 select q).ToList();
                    if (acts.Count > 0)
                    {
                        part4 = string.Format("本月进行了{0}次技术问答,{1}次事故预想", acts.Count(x => x.EduType == "2"), acts.Count(x => x.EduType == "3"));
                    }

                    //考勤
                    var part5    = string.Empty;
                    var meetings = (from q in db.IQueryable <WorkmeetingEntity>()
                                    where q.GroupId == user.BZID && q.MeetingStartTime >= start && q.MeetingEndTime <= end
                                    orderby q.MeetingStartTime
                                    select q).ToList();
                    if (meetings.Count > 0)
                    {
                        var timestamp  = meetings.Last().MeetingStartTime.Date - meetings.First().MeetingStartTime.Date;
                        var days       = Math.Ceiling(timestamp.TotalDays);
                        var matesquery = from q in db.IQueryable <PeopleEntity>()
                                         where q.BZID == user.BZID
                                         select q.ID;
                        var matescount = matesquery.Count();
                        var unsign     = (from q in db.IQueryable <UnSignRecordEntity>()
                                          where matesquery.Contains(q.UserId) && q.StartTime >= start && q.EndTime <= end
                                          select q).ToList();
                        part5 = string.Format("本月出勤率{0}", ((matescount * days - unsign.Count) / ((matescount * days) == 0 ? 1 : (matescount * days))).ToString("p"));
                    }

                    var alljobs = (from q1 in db.IQueryable <MeetingJobEntity>()
                                   join q2 in db.IQueryable <MeetingAndJobEntity>() on q1.JobId equals q2.JobId
                                   join q3 in db.IQueryable <JobUserEntity>() on q2.MeetingJobId equals q3.MeetingJobId
                                   where q1.GroupId == user.BZID && q1.IsFinished != "cancel" && q1.StartTime >= start && q1.StartTime <= end && !string.IsNullOrEmpty(q2.StartMeetingId)
                                   group new { q1.Job, q1.StartTime, q1.EndTime, q3.UserName } by new { q1.Job, q1.StartTime, q1.EndTime } into g
                                   select g).ToList();
                    groupjobs = alljobs.Select(x => new TaskEntity()
                    {
                        TaskContent = x.Key.Job, TaskPerson = string.Join(",", x.Select(y => y.UserName)), TaskPrior = string.Format("{0} ~ {1}", x.Key.StartTime.ToString("yyyy-M-d H:mm"), x.Key.EndTime.ToString("yyyy-M-d H:mm"))
                    }).ToList();
                    reportcontent = string.Join(Environment.NewLine, new string[] { part1, part2, part3, part4, part5 }.Where(x => !string.IsNullOrEmpty(x)));
                    tasks         = string.Join(Environment.NewLine, jobs.Where(x => x.IsFinished == "finish").OrderBy(x => x.StartTime).Select(x => x.Job).GroupBy(x => x).Select(x => string.Format("{0}{1}", x.Key, x.Count() > 1 ? x.Count() + "次" : string.Empty)));
                    undo          = string.Join(Environment.NewLine, jobs.Where(x => x.IsFinished == "undo").OrderBy(x => x.StartTime).Select(x => x.Job).GroupBy(x => x).Select(x => string.Format("{0}{1}", x.Key, x.Count() > 1 ? x.Count() + "次" : string.Empty)));
                }
                else
                {
                    //工作
                    var part1 = string.Empty;
                    var jobs  = (from q in db.IQueryable <MeetingJobEntity>()
                                 join q1 in db.IQueryable <MeetingAndJobEntity>() on q.JobId equals q1.JobId
                                 join q2 in db.IQueryable <JobUserEntity>() on q1.MeetingJobId equals q2.MeetingJobId
                                 where q2.UserId == user.ID && q.IsFinished != "cancel" && q.EndTime >= start && q.StartTime <= end && !string.IsNullOrEmpty(q1.StartMeetingId)
                                 select q).ToList();
                    if (jobs.Count > 0)
                    {
                        part1 = string.Format("本月安排工作任务{0}项,完成{1}项,{2}项进行中,{3}项未完成。", jobs.Count, jobs.Count(x => x.IsFinished == "finish"), jobs.Count(x => (x.IsFinished == "undo" || string.IsNullOrEmpty(x.IsFinished)) && x.EndTime > end), jobs.Count(x => (x.IsFinished == "undo" || string.IsNullOrEmpty(x.IsFinished)) && x.EndTime <= end));
                    }

                    //技术问答和事故预想
                    var part2 = string.Empty;
                    var total = (from q1 in db.IQueryable <MeetingJobEntity>()
                                 join q2 in db.IQueryable <MeetingAndJobEntity>() on q1.JobId equals q2.JobId
                                 join q3 in db.IQueryable <JobUserEntity>() on q2.MeetingJobId equals q3.MeetingJobId
                                 where q1.IsFinished != "cancel" && q1.EndTime >= start && q1.StartTime <= end && q1.GroupId == user.BZID
                                 select q3.Score).ToList();
                    var usercount = db.IQueryable <UserEntity>().Count(x => x.DepartmentId == user.BZID);
                    var avg       = (decimal)total.Sum(x => x ?? 0) / (usercount == 0 ? 1 : usercount);
                    var score     = (from q1 in db.IQueryable <MeetingJobEntity>()
                                     join q2 in db.IQueryable <MeetingAndJobEntity>() on q1.JobId equals q2.JobId
                                     join q3 in db.IQueryable <JobUserEntity>() on q2.MeetingJobId equals q3.MeetingJobId
                                     join q4 in db.IQueryable <WorkmeetingEntity>() on q2.EndMeetingId equals q4.MeetingId
                                     where q4.MeetingType == "班后会" && q1.IsFinished != "cancel" && q1.EndTime >= start && q1.StartTime <= end && q3.UserId == user.ID
                                     select q3.Score).Sum();
                    part2         = string.Format("本月班组平均绩效评分{0}分,本人得分{1}分", avg.ToString("f1"), score ?? 0);
                    reportcontent = string.Join(Environment.NewLine, new string[] { part1, part2 }.Where(x => !string.IsNullOrEmpty(x)));
                    tasks         = string.Join(Environment.NewLine, jobs.Where(x => x.IsFinished == "finish").OrderBy(x => x.StartTime).Select(x => x.Job).GroupBy(x => x).Select(x => string.Format("{0}{1}", x.Key, x.Count() > 1 ? x.Count() + "次" : string.Empty)));
                    undo          = string.Join(Environment.NewLine, jobs.Where(x => x.IsFinished == "undo").OrderBy(x => x.StartTime).Select(x => x.Job).GroupBy(x => x).Select(x => string.Format("{0}{1}", x.Key, x.Count() > 1 ? x.Count() + "次" : string.Empty)));
                }
            }
            else
            {
                if (user.Quarters == "班长" || user.Quarters == "副班长" || user.Quarters == "技术员")
                {
                    //工作
                    var part1 = string.Empty;
                    var jobs  = (from q in db.IQueryable <MeetingJobEntity>()
                                 join q1 in db.IQueryable <MeetingAndJobEntity>() on q.JobId equals q1.JobId
                                 where q.GroupId == user.BZID && q.IsFinished != "cancel" && q.EndTime >= start && q.StartTime <= end && !string.IsNullOrEmpty(q1.StartMeetingId)
                                 select q).ToList();
                    if (jobs.Count > 0)
                    {
                        part1 = string.Format("本周安排工作任务{0}项,完成{1}项,{2}进行中,{3}未完成。", jobs.Count, jobs.Count(x => x.IsFinished == "finish"), jobs.Count(x => (x.IsFinished == "undo" || string.IsNullOrEmpty(x.IsFinished)) && x.EndTime > end), jobs.Count(x => (x.IsFinished == "undo" || string.IsNullOrEmpty(x.IsFinished)) && x.EndTime <= end));
                    }

                    //危险预知训练
                    var part2   = string.Empty;
                    var dangers = (from q in db.IQueryable <DangerEntity>()
                                   where q.GroupId == user.BZID && q.Status == 2 && q.JobTime >= start && q.JobTime <= end
                                   select q).ToList();
                    if (dangers.Count > 0)
                    {
                        part2 = string.Format("本周进行危险预知训练{0}", dangers.Count);
                    }

                    //班组活动
                    var part3      = string.Empty;
                    var activities = (from q in db.IQueryable <ActivityEntity>()
                                      where q.GroupId == user.BZID && q.State == "Finish" && q.StartTime >= start && q.StartTime <= end
                                      select q).ToList();
                    if (activities.Count > 0)
                    {
                        part3 = string.Format("本周进行了{0}", string.Join(",", activities.GroupBy(x => x.ActivityType).Select(x => string.Format("{0}次{1}", x.Count(), x.Key))));
                    }

                    //技术问答和事故预想
                    var part4 = string.Empty;
                    var acts  = (from q in db.IQueryable <EduBaseInfoEntity>()
                                 where q.BZId == user.BZID && q.Flow == "1" && q.StartDate >= start && q.StartDate <= end
                                 select q).ToList();
                    if (acts.Count > 0)
                    {
                        part4 = string.Format("本周进行了{0}次技术问答,{1}次事故预想", acts.Count(x => x.EduType == "2"), acts.Count(x => x.EduType == "3"));
                    }

                    //考勤
                    var part5    = string.Empty;
                    var meetings = (from q in db.IQueryable <WorkmeetingEntity>()
                                    where q.GroupId == user.BZID && q.MeetingStartTime >= start && q.MeetingEndTime <= end
                                    orderby q.MeetingStartTime
                                    select q).ToList();
                    if (meetings.Count > 0)
                    {
                        var timestamp  = meetings.Last().MeetingStartTime.Date - meetings.First().MeetingStartTime.Date;
                        var days       = Math.Ceiling(timestamp.TotalDays);
                        var matesquery = from q in db.IQueryable <PeopleEntity>()
                                         where q.BZID == user.BZID
                                         select q.ID;
                        var matescount = matesquery.Count();
                        var unsign     = (from q in db.IQueryable <UnSignRecordEntity>()
                                          where matesquery.Contains(q.UserId) && q.StartTime >= start && q.EndTime <= end
                                          select q).ToList();
                        part5 = string.Format("本周出勤率{0}", ((matescount * days - unsign.Count) / ((matescount * days) == 0 ? 1 : (matescount * days))).ToString("p"));
                    }
                    reportcontent = string.Join(Environment.NewLine, new string[] { part1, part2, part3, part4, part5 }.Where(x => !string.IsNullOrEmpty(x)));
                    var group = jobs.Where(x => x.IsFinished == "finish").OrderBy(x => x.StartTime).Select(x => x.Job).GroupBy(x => x).ToList();
                    var sb    = new StringBuilder();
                    for (int i = 0; i < group.Count; i++)
                    {
                        sb.AppendFormat("{0}、{1}{2}{3}", (i + 1), group[i].Key, group[i].Count() > 1 ? group.Count() + "次" : string.Empty, Environment.NewLine);
                    }
                    tasks = sb.ToString();
                    group = jobs.Where(x => x.IsFinished == "undo").OrderBy(x => x.StartTime).Select(x => x.Job).GroupBy(x => x).ToList();
                    sb    = new StringBuilder();
                    for (int i = 0; i < group.Count; i++)
                    {
                        sb.AppendFormat("{0}、{1}{2}{3}", (i + 1), group[i].Key, group[i].Count() > 1 ? group.Count() + "次" : string.Empty, Environment.NewLine);
                    }
                    undo = sb.ToString();
                    //tasks = string.Join(Environment.NewLine, jobs.Where(x => x.IsFinished == "finish").OrderBy(x => x.StartTime).Select(x => x.Job).GroupBy(x => x).Select(x => string.Format("{0}{1}", x.Key, x.Count() > 1 ? x.Count() + "次" : string.Empty)));
                    //undo = string.Join(Environment.NewLine, jobs.Where(x => x.IsFinished == "undo").OrderBy(x => x.StartTime).Select(x => x.Job).GroupBy(x => x).Select(x => string.Format("{0}{1}", x.Key, x.Count() > 1 ? x.Count() + "次" : string.Empty)));
                }
                else
                {
                    //工作
                    var part1 = string.Empty;
                    var jobs  = (from q in db.IQueryable <MeetingJobEntity>()
                                 join q1 in db.IQueryable <MeetingAndJobEntity>() on q.JobId equals q1.JobId
                                 join q2 in db.IQueryable <JobUserEntity>() on q1.MeetingJobId equals q2.MeetingJobId
                                 where q2.UserId == user.ID && q.IsFinished != "cancel" && q.EndTime >= start && q.StartTime <= end && !string.IsNullOrEmpty(q1.StartMeetingId)
                                 select q).ToList();
                    if (jobs.Count > 0)
                    {
                        part1 = string.Format("本周安排工作任务{0}项,完成{1}项,{2}项进行中,{3}项未完成。", jobs.Count, jobs.Count(x => x.IsFinished == "finish"), jobs.Count(x => (x.IsFinished == "undo" || string.IsNullOrEmpty(x.IsFinished)) && x.EndTime > end), jobs.Count(x => (x.IsFinished == "undo" || string.IsNullOrEmpty(x.IsFinished)) && x.EndTime <= end));
                    }

                    //技术问答和事故预想
                    var part2 = string.Empty;
                    var acts  = (from q in db.IQueryable <EduBaseInfoEntity>()
                                 where q.BZId == user.BZID && q.Flow == "1" && q.StartDate >= start && q.StartDate <= end
                                 select q).ToList();
                    if (acts.Count > 0)
                    {
                        part2 = string.Format("本周进行了{0}次培训", acts.Count);
                    }
                    reportcontent = string.Join(Environment.NewLine, new string[] { part1, part2 }.Where(x => !string.IsNullOrEmpty(x)));
                    var group = jobs.Where(x => x.IsFinished == "finish").OrderBy(x => x.StartTime).Select(x => x.Job).GroupBy(x => x).ToList();
                    var sb    = new StringBuilder();
                    for (int i = 0; i < group.Count; i++)
                    {
                        sb.AppendFormat("{0}、{1}{2}{3}", (i + 1), group[i].Key, group[i].Count() > 1 ? group.Count() + "次" : string.Empty, Environment.NewLine);
                    }
                    tasks = sb.ToString();
                    group = jobs.Where(x => x.IsFinished == "undo").OrderBy(x => x.StartTime).Select(x => x.Job).GroupBy(x => x).ToList();
                    sb    = new StringBuilder();
                    for (int i = 0; i < group.Count; i++)
                    {
                        sb.AppendFormat("{0}、{1}{2}{3}", (i + 1), group[i].Key, group[i].Count() > 1 ? group.Count() + "次" : string.Empty, Environment.NewLine);
                    }
                    undo = sb.ToString();
                    //tasks = string.Join(Environment.NewLine, jobs.Where(x => x.IsFinished == "finish").OrderBy(x => x.StartTime).Select(x => x.Job).GroupBy(x => x).Select(x => string.Format("{0}{1}", x.Key, x.Count() > 1 ? x.Count() + "次" : string.Empty)));
                    //undo = string.Join(Environment.NewLine, jobs.Where(x => x.IsFinished == "undo").OrderBy(x => x.StartTime).Select(x => x.Job).GroupBy(x => x).Select(x => string.Format("{0}{1}", x.Key, x.Count() > 1 ? x.Count() + "次" : string.Empty)));
                }
            }

            var result = new ReportEntity {
                ReportId = Guid.NewGuid(), ReportContent = reportcontent, ReportTime = DateTime.Now, ReportType = reporttype, ReportUser = user.Name, StartTime = start, EndTime = end, Tasks = tasks, Undo = undo, TaskList = groupjobs
            };

            return(result);
        }
Esempio n. 12
0
 public void Update(PeopleEntity entity)
 {
     service.Update(entity);
 }