Exemplo n.º 1
0
        public async Task <RepResult <PersonnelVM> > Login(string nationalCode, string passWord)
        {
            if (dbContext != null)
            {
                var query = from prs in dbContext.Personnels join user in dbContext.Users on prs.PersonnelId equals user.PersonnelId
                            where prs.NationalCode == nationalCode && user.Password == passWord select prs;


                if (await query.AnyAsync())
                {
                    var obj = await query.Include(c => c.Users).SingleOrDefaultAsync();

                    PersonnelRepository.LoadUser(obj);
                    return(new RepResult <PersonnelVM> {
                        Successed = true, ResultObject = PersonnelVM.GetVM(obj)
                    });
                }
                else
                {
                    return(new RepResult <PersonnelVM> {
                        Successed = false,
                        Message = "پرسنل با این کد ملی و پسورد در سیستم موجود نمی باشد"
                    });
                }
            }

            return(new RepResult <PersonnelVM>());
        }
        public async Task <RepResult <PersonnelVM> > Get(int id)
        {
            if (dbContext != null)
            {
                var obj = await entity.Include(c => c.Users).SingleOrDefaultAsync(s => s.PersonnelId == id);

                LoadUser(obj);

                return(new RepResult <PersonnelVM> {
                    Successed = true, ResultObject = PersonnelVM.GetVM(obj)
                });
            }

            return(new RepResult <PersonnelVM>());
        }
        public async Task <RepResult <IEnumerable <PersonnelVM> > > Get()
        {
            if (dbContext != null)
            {
                var objs = await entity.Include(c => c.Users).ToAsyncEnumerable().ToList();

                foreach (Personnel obj in objs)
                {
                    LoadUser(obj);
                }

                return(new RepResult <IEnumerable <PersonnelVM> > {
                    Successed = true, ResultObject = objs.Select(m => PersonnelVM.GetVM(m))
                });
            }

            return(new RepResult <IEnumerable <PersonnelVM> >());
        }