Exemplo n.º 1
0
            public async Task <Unit> Handle(Command request, CancellationToken cancellationToken)
            {
                _context.Set <DbFacProgramDetail>().RemoveRange(request.dbFacProgramDetail.Where(o => o.RowState == RowState.Delete));
                await _context.SaveChangesAsync(cancellationToken);

                request.dbFacProgramDetail = request.dbFacProgramDetail.Where(o => o.RowState != RowState.Delete).ToList();

                foreach (var group in request.dbFacProgramDetail.Where(o => o.RowState == RowState.Add))
                {
                    if (_context.Set <DbFacProgramDetail>().Any(o => o.CompanyCode == request.CompanyCode & o.FacCode == group.FacCode
                                                                & o.ProgramCode == group.ProgramCode & o.DepartmentCode == group.DepartmentCode))
                    {
                        throw new RestException(HttpStatusCode.BadRequest, "message.STD00004", "label.DBRT21.DepartmentCode");
                    }
                    _context.Set <DbFacProgramDetail>().Add(group);
                    _context.Entry(group).State = EntityState.Added;
                    await _context.SaveChangesAsync(cancellationToken);
                }

                foreach (var group in request.dbFacProgramDetail.Where(o => o.RowState == RowState.Edit))
                {
                    _context.Set <DbFacProgramDetail>().Attach(group);
                    _context.Entry(group).State = EntityState.Modified;
                }

                _context.Set <DbFacProgram>().Attach((DbFacProgram)request);
                _context.Entry((DbFacProgram)request).State = EntityState.Modified;
                await _context.SaveChangesAsync(cancellationToken);

                return(Unit.Value);
            }
Exemplo n.º 2
0
            public async Task <long> Handle(Command request, CancellationToken cancellationToken)
            {
                _context.Set <DbDegreeSubEduGroup>().RemoveRange(request.dbDegreeSubEduGroup.Where(o => o.RowState == RowState.Delete));
                await _context.SaveChangesAsync(cancellationToken);

                request.dbDegreeSubEduGroup = request.dbDegreeSubEduGroup.Where(o => o.RowState != RowState.Delete).ToList();


                foreach (var group in request.dbDegreeSubEduGroup.Where(o => o.RowState == RowState.Add))
                {
                }

                foreach (var group in request.dbDegreeSubEduGroup.Where(o => o.RowState == RowState.Edit))
                {
                    _context.Set <DbDegreeSubEduGroup>().Attach(group);
                    _context.Entry(group).State = EntityState.Modified;
                }

                _context.Set <DbDegreeSub>().Attach((DbDegreeSub)request);
                _context.Entry((DbDegreeSub)request).State = EntityState.Modified;

                await _context.SaveChangesAsync(cancellationToken);

                return(request.SubDegreeId);
            }
Exemplo n.º 3
0
            public async Task <Unit> Handle(Command request, CancellationToken cancellationToken)
            {
                _context.Set <DbRegion>().Attach((DbRegion)request);
                _context.Entry((DbRegion)request).State = EntityState.Modified;
                await _context.SaveChangesAsync(cancellationToken);

                return(Unit.Value);
            }
Exemplo n.º 4
0
            public async Task <long?> Handle(Command request, CancellationToken cancellationToken)
            {
                _context.Set <DbPostalCode>().Attach((DbPostalCode)request);
                _context.Entry((DbPostalCode)request).State = EntityState.Modified;
                await _context.SaveChangesAsync(cancellationToken);

                return(request.PostalCodeId);
            }
Exemplo n.º 5
0
            public async Task <Unit> Handle(Command request, CancellationToken cancellationToken)
            {
                _context.Set <SuProgramLabel>().RemoveRange(request.ProgramLabels.Where(o => o.RowState == RowState.Delete));
                await _context.SaveChangesAsync(cancellationToken);

                request.ProgramLabels = request.ProgramLabels.Where(o => o.RowState != RowState.Delete).ToList();

                foreach (var room in request.ProgramLabels.Where(o => o.RowState == RowState.Edit))
                {
                    _context.Set <SuProgramLabel>().Attach(room);
                    _context.Entry(room).State = EntityState.Modified;
                }

                _context.Set <SuProgram>().Attach((SuProgram)request);
                _context.Entry((SuProgram)request).State = EntityState.Modified;
                await _context.SaveChangesAsync(cancellationToken);

                return(Unit.Value);
            }
Exemplo n.º 6
0
            public async Task <Unit> Handle(Command request, CancellationToken cancellationToken)
            {
                var company = await _context.Set <SuCompany>().Include(i => i.Divisions).ThenInclude(i => i.Divisions).FirstOrDefaultAsync(i => i.CompanyCode == request.CompanyCode);

                _context.Entry(company).Property("RowVersion").OriginalValue = request.RowVersion;
                _context.Set <SuCompany>().Remove(company);
                await _context.SaveChangesAsync(cancellationToken);

                return(Unit.Value);
            }
Exemplo n.º 7
0
            public async Task <Unit> Handle(Command request, CancellationToken cancellationToken)
            {
                var menu = await _context.Set <SuMenu>().Include(i => i.MenuLabels).FirstOrDefaultAsync(i => i.MenuCode == request.MenuCode);

                _context.Entry(menu).Property("RowVersion").OriginalValue = request.RowVersion;
                _context.Set <SuMenu>().Remove(menu);
                await _context.SaveChangesAsync(cancellationToken);

                return(Unit.Value);
            }
Exemplo n.º 8
0
            public async Task <Unit> Handle(Command request, CancellationToken cancellationToken)
            {
                var user = await _context.Set <SuUser>().Where(o => o.Id == request.Id).FirstOrDefaultAsync(cancellationToken);

                _context.Entry(user).Property("RowVersion").OriginalValue = request.RowVersion;
                user.ForceChangePassword = request.ForceChangePassword;
                user.Active             = request.Active;
                user.DefaultLang        = request.DefaultLang;
                user.PasswordPolicyCode = request.PasswordPolicyCode;
                user.StartEffectiveDate = request.StartEffectiveDate;
                user.EndEffectiveDate   = request.EndEffectiveDate;
                user.UpdatedBy          = _user.UserName;
                user.UpdatedDate        = DateTime.Now;
                user.UpdatedProgram     = _user.ProgramCode;
                var result = await _identity.UpdateUserAsync(user);

                if (!result.Succeeded)
                {
                    throw new RestException(System.Net.HttpStatusCode.InternalServerError, String.Join(",", result.Errors));
                }

                _context.Set <SuUserProfile>().RemoveRange(request.Profiles.Where(o => o.RowState == RowState.Delete));
                await _context.SaveChangesAsync(cancellationToken);

                request.Profiles = request.Profiles.Where(o => o.RowState != RowState.Delete).ToList();

                _context.Set <SuUserProfile>().AddRange(request.Profiles);

                foreach (var permission in request.Permissions.Where(o => o.RowState == RowState.Delete))
                {
                    var userPermission = await _context.Set <SuUserPermission>().Include(g => g.Divisions).Include(g => g.EduLevels)
                                         .FirstOrDefaultAsync(g => g.Id == permission.Id && g.CompanyCode == permission.CompanyCode);

                    _context.Entry(userPermission).Property("RowVersion").OriginalValue = permission.RowVersion;
                    _context.Set <SuUserPermission>().Remove(userPermission);
                }

                await _context.SaveChangesAsync(cancellationToken);

                return(Unit.Value);
            }
Exemplo n.º 9
0
            public async Task <Unit> Handle(Command request, CancellationToken cancellationToken)
            {
                request.tNameConcat = await this.GetEmployeeConcatTha(request, cancellationToken);

                request.eNameConcat = await this.GetEmployeeConcatEng(request, cancellationToken);

                _context.Set <DbEmployee>().Attach((DbEmployee)request);
                _context.Entry((DbEmployee)request).State = EntityState.Modified;
                await _context.SaveChangesAsync(cancellationToken);

                return(Unit.Value);
            }
Exemplo n.º 10
0
            public async Task <long> Handle(Command request, CancellationToken cancellationToken)
            {
                _context.Set <DbRoom>().RemoveRange(request.dbRoom.Where(o => o.RowState == RowState.Delete));
                await _context.SaveChangesAsync(cancellationToken);

                request.dbRoom = request.dbRoom.Where(o => o.RowState != RowState.Delete).ToList();


                foreach (var group in request.dbRoom.Where(o => o.RowState == RowState.Add))
                {
                }
                foreach (var group in request.dbRoom.Where(o => o.RowState == RowState.Edit))
                {
                    _context.Set <DbRoom>().Attach(group);
                    _context.Entry(group).State = EntityState.Modified;
                }

                _context.Set <DbPrivilegeBuilding>().RemoveRange(request.dbPrivilegeBuilding.Where(o => o.RowState == RowState.Delete));
                await _context.SaveChangesAsync(cancellationToken);

                request.dbPrivilegeBuilding = request.dbPrivilegeBuilding.Where(o => o.RowState != RowState.Delete).ToList();


                foreach (var group in request.dbPrivilegeBuilding.Where(o => o.RowState == RowState.Add))
                {
                }
                foreach (var group in request.dbPrivilegeBuilding.Where(o => o.RowState == RowState.Edit))
                {
                    _context.Set <DbPrivilegeBuilding>().Attach(group);
                    _context.Entry(group).State = EntityState.Modified;
                }

                _context.Set <DbBuilding>().Attach((DbBuilding)request);
                _context.Entry((DbBuilding)request).State = EntityState.Modified;

                await _context.SaveChangesAsync(cancellationToken);

                return(request.BuildingId);
            }
Exemplo n.º 11
0
            public async Task <Unit> Handle(Command request, CancellationToken cancellationToken)
            {
                request.ProgramLabels.Clear();
                var programLabels = await _context.Set <SuProgramLabel>().Where(i => i.ProgramCode == request.ProgramCode && i.LangCode == Lang.th).AsNoTracking().ToListAsync(cancellationToken);

                foreach (SuProgramLabel item in programLabels)
                {
                    request.ProgramLabels.Add(new SuProgramLabel {
                        RowState = RowState.Add, FieldName = item.FieldName, LangCode = Lang.en, LabelName = item.LabelName, SystemCode = item.SystemCode, ModuleCode = item.ModuleCode
                    });
                }

                _context.Set <SuProgram>().Attach((SuProgram)request);
                _context.Entry((SuProgram)request).State = EntityState.Modified;
                await _context.SaveChangesAsync(cancellationToken);

                return(Unit.Value);
            }
Exemplo n.º 12
0
            public async Task <Unit> Handle(Command request, CancellationToken cancellationToken)
            {
                _context.Set <SuUserDivision>().RemoveRange(request.Divisions.Where(o => o.RowState == RowState.Delete));
                await _context.SaveChangesAsync(cancellationToken);

                request.Divisions = request.Divisions.Where(o => o.RowState == RowState.Add).ToList();

                _context.Set <SuUserEduLevel>().RemoveRange(request.EduLevels.Where(o => o.RowState == RowState.Delete));
                await _context.SaveChangesAsync(cancellationToken);

                request.EduLevels = request.EduLevels.Where(o => o.RowState == RowState.Add).ToList();

                _context.Set <SuUserPermission>().Attach((SuUserPermission)request);
                _context.Entry((SuUserPermission)request).State = EntityState.Modified;
                await _context.SaveChangesAsync(cancellationToken);

                return(Unit.Value);
            }
Exemplo n.º 13
0
            public async Task <Unit> Handle(Command request, CancellationToken cancellationToken)
            {
                _context.Set <SuMenuProfile>().RemoveRange(request.MenuProfiles.Where(i => i.RowState == RowState.Delete));
                await _context.SaveChangesAsync(cancellationToken);

                request.MenuProfiles = request.MenuProfiles.Where(i => i.RowState != RowState.Delete).ToList();

                //foreach (var menu in request.MenuProfiles.Where(i => i.RowState == RowState.Normal))
                //{
                //    if (_context.Set<SuMenuProfile>().Any(i => i.MenuCode == menu.MenuCode))
                //        request.MenuProfiles.Remove(menu);
                //}

                _context.Set <SuProfile>().Attach((SuProfile)request);
                _context.Entry((SuProfile)request).State = EntityState.Modified;
                await _context.SaveChangesAsync(cancellationToken);

                return(Unit.Value);
            }