Esempio n. 1
0
            public async Task <Unit> Handle(Command request, CancellationToken cancellationToken)
            {
                if (_context.Set <SuProfile>().Any(i => i.ProfileCode.ToUpper() == request.ProfileCodeTo.ToUpper()))
                {
                    throw new RestException(HttpStatusCode.BadRequest, "message.SU00043");
                }

                SuProfile suProfile = new SuProfile();

                suProfile.ProfileCode = request.ProfileCodeTo;
                suProfile.ProfileDesc = request.ProfileDescTo;
                suProfile.Active      = true;
                _context.Set <SuProfile>().Add((SuProfile)suProfile);
                await _context.SaveChangesAsync(cancellationToken);

                List <SuMenuProfile> suMenuProfiles = await _context.Set <SuMenuProfile>().Where(e => e.ProfileCode == request.ProfileCodeFrom).AsNoTracking().ToListAsync(cancellationToken);

                foreach (SuMenuProfile suMenuProfile in suMenuProfiles)
                {
                    suMenuProfile.ProfileCode = request.ProfileCodeTo;
                }

                _context.Set <SuMenuProfile>().AddRange(suMenuProfiles);
                await _context.SaveChangesAsync(cancellationToken);

                return(Unit.Value);
            }
Esempio 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);
            }
Esempio n. 3
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);
            }
Esempio n. 4
0
            public async Task <long?> Handle(Command request, CancellationToken cancellationToken)
            {
                _context.Set <DbRegion>().Add((DbRegion)request);
                await _context.SaveChangesAsync(cancellationToken);

                return(request.RegionId);
            }
Esempio n. 5
0
            public async Task <long> Handle(Command request, CancellationToken cancellationToken)
            {
                _context.Set <DbDegree>().Add((DbDegree)request);
                await _context.SaveChangesAsync(cancellationToken);

                return(request.DegreeId);
            }
Esempio n. 6
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);
            }
Esempio n. 7
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);
            }
            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);
            }
Esempio n. 9
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);
            }
Esempio n. 10
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);
            }
Esempio n. 11
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);
            }
Esempio n. 12
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);
            }
Esempio n. 13
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);
            }
Esempio n. 14
0
            public async Task <Unit> Handle(Command request, CancellationToken cancellationToken)
            {
                if (_context.Set <SuDivision>().Any(i => i.CompanyCode == request.CompanyCode && i.DivCode.ToUpper() == request.DivCode.ToUpper()))
                {
                    throw new RestException(HttpStatusCode.BadRequest, "message.STD00004", "label.SURT01.DivCode");
                }

                _context.Set <SuDivision>().Add((SuDivision)request);
                await _context.SaveChangesAsync(cancellationToken);

                return(Unit.Value);
            }
Esempio n. 15
0
            public async Task <Unit> Handle(Command request, CancellationToken cancellationToken)
            {
                var region = new DbRegion {
                    RegionId = request.RegionId, RowVersion = request.RowVersion
                };

                _context.Set <DbRegion>().Attach(region);
                _context.Set <DbRegion>().Remove(region);
                await _context.SaveChangesAsync(cancellationToken);

                return(Unit.Value);
            }
Esempio n. 16
0
            public async Task <Unit> Handle(Command request, CancellationToken cancellationToken)
            {
                if (_context.Set <DbListItem>().Any(o => o.ListItemGroupCode == request.ListItemGroupCode && o.ListItemCode == request.ListItemCode))
                {
                    throw new RestException(HttpStatusCode.BadRequest, "message.STD00004", "label.DBRT18.listItemCode");
                }

                _context.Set <DbListItem>().Add((DbListItem)request);
                await _context.SaveChangesAsync(cancellationToken);

                return(Unit.Value);
            }
Esempio n. 17
0
            public async Task <Unit> Handle(Command request, CancellationToken cancellationToken)
            {
                if (_context.Set <DbEducationTypeLevel>().Any(o => o.CompanyCode == _user.Company && o.EducationTypeLevel == request.EducationTypeLevel))
                {
                    throw new Common.Exceptions.RestException(HttpStatusCode.BadRequest, "message.STD00004", "label.DBRT09.educationTypeLevel");
                }
                request.CompanyCode = _user.Company;
                _context.Set <DbEducationTypeLevel>().Add((DbEducationTypeLevel)request);
                await _context.SaveChangesAsync(cancellationToken);

                return(Unit.Value);
            }
Esempio n. 18
0
            public async Task <Unit> Handle(Command request, CancellationToken cancellationToken)
            {
                var subdistrict = new DbSubDistrict {
                    SubDistrictId = request.SubDistrictId, RowVersion = request.RowVersion
                };

                _context.Set <DbSubDistrict>().Attach(subdistrict);
                _context.Set <DbSubDistrict>().Remove(subdistrict);
                await _context.SaveChangesAsync(cancellationToken);

                return(Unit.Value);
            }
Esempio n. 19
0
            public async Task <Unit> Handle(Command request, CancellationToken cancellationToken)
            {
                if (_context.Set <DbFac>().Any(o => o.CompanyCode == request.CompanyCode && o.FacCode == request.FacCode))
                {
                    throw new RestException(HttpStatusCode.BadRequest, "message.STD00004", "label.DBRT11.facCode");
                }
                request.CompanyCode = _user.Company;
                _context.Set <DbFac>().Add((DbFac)request);
                await _context.SaveChangesAsync(cancellationToken);

                return(Unit.Value);
            }
Esempio n. 20
0
            public async Task <Unit> Handle(Command request, CancellationToken cancellationToken)
            {
                var educationtype = new DbEducationType {
                    CompanyCode = _user.Company, EducationTypeCode = request.EducationTypeCode, RowVersion = request.RowVersion
                };

                _context.Set <DbEducationType>().Attach(educationtype);
                _context.Set <DbEducationType>().Remove(educationtype);
                await _context.SaveChangesAsync(cancellationToken);

                return(Unit.Value);
            }
Esempio n. 21
0
            public async Task <Unit> Handle(Command request, CancellationToken cancellationToken)
            {
                var country = new DbCountry {
                    CountryId = request.CountryId, RowVersion = request.RowVersion
                };

                _context.Set <DbCountry>().Attach(country);
                _context.Set <DbCountry>().Remove(country);
                await _context.SaveChangesAsync(cancellationToken);

                return(Unit.Value);
            }
Esempio n. 22
0
            public async Task <Unit> Handle(Command request, CancellationToken cancellationToken)
            {
                var department = new DbDepartment {
                    DepartmentCode = request.DepartmentCode, RowVersion = request.RowVersion
                };

                _context.Set <DbDepartment>().Attach(department);
                _context.Set <DbDepartment>().Remove(department);
                await _context.SaveChangesAsync(cancellationToken);

                return(Unit.Value);
            }
Esempio n. 23
0
            public async Task <long> Handle(Command request, CancellationToken cancellationToken)
            {
                if (_context.Set <DbBuilding>().Any(o => o.CompanyCode == _user.Company && o.BuildingId == request.BuildingId))
                {
                    throw new Common.Exceptions.RestException(HttpStatusCode.BadRequest, "message.STD00004", "label.DBRT17.buildingCode");
                }
                request.CompanyCode = _user.Company;
                _context.Set <DbBuilding>().Add((DbBuilding)request);
                await _context.SaveChangesAsync(cancellationToken);

                return(request.BuildingId);
            }
Esempio n. 24
0
            public async Task <Unit> Handle(Command request, CancellationToken cancellationToken)
            {
                var building = new DbBuilding {
                    BuildingId = request.BuildingId, RowVersion = request.RowVersion
                };

                _context.Set <DbBuilding>().Attach(building);
                _context.Set <DbBuilding>().Remove(building);
                await _context.SaveChangesAsync(cancellationToken);

                return(Unit.Value);
            }
Esempio n. 25
0
            public async Task <Unit> Handle(Command request, CancellationToken cancellationToken)
            {
                var province = new DbProvince {
                    ProvinceId = request.ProvinceId, RowVersion = request.RowVersion
                };

                _context.Set <DbProvince>().Attach(province);
                _context.Set <DbProvince>().Remove(province);
                await _context.SaveChangesAsync(cancellationToken);

                return(Unit.Value);
            }
Esempio n. 26
0
            public async Task <Unit> Handle(Command request, CancellationToken cancellationToken)
            {
                var location = new DbLocation {
                    CompanyCode = request.CompanyCode, LocationCode = request.LocationCode, RowVersion = request.RowVersion
                };

                _context.Set <DbLocation>().Attach(location);
                _context.Set <DbLocation>().Remove(location);
                await _context.SaveChangesAsync(cancellationToken);

                return(Unit.Value);
            }
Esempio n. 27
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);
            }
Esempio n. 28
0
            public async Task <Unit> Handle(Command request, CancellationToken cancellationToken)
            {
                SuPasswordPolicy passwordPolicy = new SuPasswordPolicy {
                    PasswordPolicyCode = request.PasswordPolicyCode, RowVersion = request.RowVersion
                };

                _context.Set <SuPasswordPolicy>().Attach(passwordPolicy);
                _context.Set <SuPasswordPolicy>().Remove(passwordPolicy);
                await _context.SaveChangesAsync(cancellationToken);

                return(Unit.Value);
            }
Esempio n. 29
0
            public async Task <Unit> Handle(Command request, CancellationToken cancellationToken)
            {
                var subdegreetype = new DbDegreeSub {
                    SubDegreeId = request.SubDegreeId, RowVersion = request.RowVersion
                };

                _context.Set <DbDegreeSub>().Attach(subdegreetype);
                _context.Set <DbDegreeSub>().Remove(subdegreetype);
                await _context.SaveChangesAsync(cancellationToken);

                return(Unit.Value);
            }
Esempio n. 30
0
            public async Task <Unit> Handle(Command request, CancellationToken cancellationToken)
            {
                if (await _context.Set <SuUserPermission>().AnyAsync(o => o.Id == request.Id && o.CompanyCode == request.CompanyCode, cancellationToken))
                {
                    throw new RestException(HttpStatusCode.BadRequest, "message.STD00004", "label.SURT06.CompanyCode");
                }

                _context.Set <SuUserPermission>().Add(request);
                await _context.SaveChangesAsync(cancellationToken);

                return(Unit.Value);
            }