コード例 #1
0
        public bool IsRecordHasNewValue(ValueHistoryRecord record)
        {
            var hasNewValue = false;

            if (Records.Any(r => r.PropertyName == record.PropertyName))
            {
                var lastRecord = Records.Where(r => r.PropertyName == record.PropertyName)
                                 .OrderByDescending(r => r.RecordDate)
                                 .First();

                var setting = Settings.FirstOrDefault(s => s.PropertyName == record.PropertyName);

                if (setting.ControlActionWhetherValueIsNew != null)
                {
                    hasNewValue = setting.ControlActionWhetherValueIsNew(lastRecord.Value, record.Value);
                }
                else
                {
                    hasNewValue = true;
                }
            }
            else
            {
                hasNewValue = true;
            }

            return(hasNewValue);
        }
コード例 #2
0
        public async Task OnGetAsync()
        {
            Records = await _mapper.ProjectTo <vm_采购询价>(_pinhua2.tb_报价表)
                      .Where(m => m.业务类型 == "采购询价").OrderByDescending(m => m.交期).ThenByDescending(m => m.单号).ToListAsync();

            RecordsDs = await _mapper.ProjectTo <vm_采购询价D>(_pinhua2.tb_报价表D)
                        .Where(m => Records.Any(r => r.RecordId == m.RecordId)).OrderByDescending(m => m.RecordId).ThenBy(m => m.RN).ToListAsync();

            templateModel = new _CRUD_Template_Model_Index
            {
                RecordMains = new _CRUD_Template_Model_Details
                {
                    Title = "采购询价",
                    Data  = Records.Cast <object>()
                },
                RecordDetailsArray = new List <_CRUD_Template_Model_Details>
                {
                    new _CRUD_Template_Model_Details
                    {
                        Title = "明细",
                        Url   = "/api/mm/询价/",
                        Data  = RecordsDs
                    },
                },
            };
        }
コード例 #3
0
 private void InitProducts()
 {
     if (Records == null || !Records.Any())
     {
         Records = new List <MediaDigitalInfoRecord>();
     }
 }
コード例 #4
0
 public override Course Add(Course record)
 {
     if (Records.Any(x => x.Name == record.Name))
     {
         throw new CustomDbException("Course name existed.");
     }
     return(base.Add(record));
 }
コード例 #5
0
        public void ReadRecords(string fileName)
        {
            Records = _adifRecordService.ReadRecords(fileName);

            if (!Records.Any())
            {
                MainGrid?.InvalidateVisual();
            }
        }
コード例 #6
0
ファイル: UserRepository.cs プロジェクト: AmChaoSun/studyhub
        public User EditUser(UserEditDto info)
        {
            //check username
            if (Records
                .Any(x => x.Id != info.Id && x.NickName == info.NickName))
            {
                throw new CustomDbException("user name existed");
            }

            var role = context.UserRoles
                .Where(x => x.Name == info.Role)
                .FirstOrDefault();

            if(role == null)
            {
                throw new CustomDbException("Invalid role value");
            }

            var user = Records
                .Include(x => x.Role)
                .FirstOrDefault(x => x.Id == info.Id);

            if (user == null)
            {
                throw new CustomDbException("User not Found");
            }

            var entry = context.Entry(user);
            entry.CurrentValues.SetValues(new { 
                info.NickName,
                info.Mobile,
                info.IsActive,
                info.Email,
                role.RoleId,
                Role = role
            });
            entry.State = EntityState.Modified;
            context.SaveChanges();
            return user;
        }
コード例 #7
0
        public Course UpdateCourse(CourseUpdateDto info)
        {
            //check publisher has auth to publish
            var user = context.Users
                       .Include(x => x.Role)
                       .Where(x => x.Id == info.PublisherId)
                       .FirstOrDefault();

            if (!CanPublish(user))
            {
                throw new UnauthorizedAccessException();
            }

            //check course to be updated exists
            var course = Records
                         .Where(x => x.CourseId == info.CourseId &&
                                x.PublisherId == info.PublisherId)
                         .FirstOrDefault();

            if (course == null)
            {
                throw new UnauthorizedAccessException();
            }

            //check values
            if (Records
                .Any(x => x.CourseId != info.CourseId && x.Name == info.Name))
            {
                throw new CustomDbException("course name existed");
            }

            //update
            var entry = context.Entry(course);

            entry.CurrentValues.SetValues(info);
            entry.State = EntityState.Modified;
            context.SaveChanges();
            return(course);
        }
コード例 #8
0
        public bool HasChangedFor(ValueHistoryRecord record)
        {
            if (IsRecordHasNewValue(record))
            {
                if (Records.Count > 0 && Records.Any(r => r.PropertyName == record.PropertyName))
                {
                    var maxRecordDate = Records.Where(r => r.PropertyName == record.PropertyName).Max(r => r.RecordDate);

                    if (maxRecordDate >= record.RecordDate)
                    {
                        record.RecordDate = maxRecordDate.AddTicks(1);
                    }
                }

                Records.Add(record);

                Update();

                return(true);
            }

            return(false);
        }
コード例 #9
0
ファイル: UserRepository.cs プロジェクト: AmChaoSun/studyhub
        public void StudentEnrollCourse(int studentId, int courseId)
        {
            if(context.Enrolls
                .Any(x => x.CourseId == courseId && x.UserId == studentId))
            {
                throw new CustomDbException("Already enrolled.");
            }
            if(!context.Courses.Any(x => x.CourseId == courseId))
            {
                throw new CustomDbException("Course not found.");
            }
            if(!Records.Any(x => x.Id == studentId))
            {
                throw new CustomDbException("Student not found.");
            }

            context.Enrolls.Add(new Enroll
            {
                UserId = studentId,
                CourseId = courseId
            });
            context.SaveChanges();
        }
コード例 #10
0
        public Course RegisterCourse(Course course)
        {
            var user = context.Users
                       .Include(x => x.Role)
                       .Where(x => x.Id == course.PublisherId)
                       .FirstOrDefault();

            //check user has auth to publish or not
            if (!CanPublish(user))
            {
                throw new UnauthorizedAccessException();
            }

            if (Records.Any(x => x.Name == course.Name))
            {
                throw new CustomDbException("Course name existed.");
            }

            course.Publisher = user;
            context.Add(course);
            context.SaveChanges();
            return(course);
        }
コード例 #11
0
        /// <summary>
        /// Creates an instance of <see cref="T:Caliburn.Micro.PropertyChangedBase"/>.
        /// </summary>
        public ActivityRecordsLogChartPiece(
            Activity activity,
            IEnumerable <ActivityRecord> records,
            TimeSpan workdayDuration)
        {
            _activity = activity;
            Records   = records.ToList();

            if (Records == null || !Records.Any())
            {
                return;
            }

            TotalDuration = (int)Math.Round(TimeSpan.FromTicks(Records.Sum(r => r.DurationTicks)).TotalMinutes);

            var totalWorkdayMinutes = (int)Math.Round(workdayDuration.TotalMinutes);

            if (totalWorkdayMinutes == 0)
            {
                return;
            }

            WorkdayPercent = (int)(TotalDuration / (totalWorkdayMinutes / 100d));
        }
コード例 #12
0
 private bool ContainsRecord(string recordName)
 {
     return(Records.Any(node => node.Name == recordName));
 }
コード例 #13
0
ファイル: BoardRepository.cs プロジェクト: crazyants/forum
        public ServiceModels.ServiceResponse AddBoard(InputModels.CreateBoardInput input)
        {
            var serviceResponse = new ServiceModels.ServiceResponse();

            if (Records.Any(b => b.Name == input.Name))
            {
                serviceResponse.Error(nameof(input.Name), "A board with that name already exists");
            }

            DataModels.Category categoryRecord = null;

            if (!string.IsNullOrEmpty(input.NewCategory))
            {
                input.NewCategory = input.NewCategory.Trim();
            }

            if (!string.IsNullOrEmpty(input.NewCategory))
            {
                categoryRecord = Categories.FirstOrDefault(c => c.Name == input.NewCategory);

                if (categoryRecord is null)
                {
                    var displayOrder = Categories.DefaultIfEmpty().Max(c => c.DisplayOrder);

                    categoryRecord = new DataModels.Category {
                        Name         = input.NewCategory,
                        DisplayOrder = displayOrder + 1
                    };

                    DbContext.Categories.Add(categoryRecord);
                }
            }
            else
            {
                try {
                    var categoryId = Convert.ToInt32(input.Category);
                    categoryRecord = Categories.First(c => c.Id == categoryId);

                    if (categoryRecord is null)
                    {
                        serviceResponse.Error(nameof(input.Category), "No category was found with this ID.");
                    }
                }
                catch (FormatException) {
                    serviceResponse.Error(nameof(input.Category), "Invalid category ID");
                }
            }

            if (!string.IsNullOrEmpty(input.Name))
            {
                input.Name = input.Name.Trim();
            }

            if (string.IsNullOrEmpty(input.Name))
            {
                serviceResponse.Error(nameof(input.Name), "Name is a required field.");
            }

            if (!string.IsNullOrEmpty(input.Description))
            {
                input.Description = input.Description.Trim();
            }

            var existingRecord = Records.FirstOrDefault(b => b.Name == input.Name);

            if (existingRecord != null)
            {
                serviceResponse.Error(nameof(input.Name), "A board with that name already exists");
            }

            if (!serviceResponse.Success)
            {
                return(serviceResponse);
            }

            DbContext.SaveChanges();

            var record = new DataModels.Board {
                Name        = input.Name,
                Description = input.Description,
                CategoryId  = categoryRecord.Id
            };

            DbContext.Boards.Add(record);

            DbContext.SaveChanges();

            serviceResponse.RedirectPath = UrlHelper.Action(nameof(Controllers.Boards.Manage), nameof(Controllers.Boards), new { id = record.Id });

            return(serviceResponse);
        }