Beispiel #1
0
        public staffviewmodel GetInforById(int id)
        {
            staffviewmodel res       = new staffviewmodel();
            var            staff_cur = _dbContext.staffs.Where(i => i.sta_id == id).FirstOrDefault();
            var            satffview = _mapper.Map <staffviewmodel>(staff_cur);

            res = satffview;
            var deparment = _dbContext.departments.FirstOrDefault(x => x.de_id == staff_cur.department_id);

            res.department_name = deparment.de_name;
            var position = _dbContext.positions.FirstOrDefault(x => x.pos_id == staff_cur.position_id);

            res.position_name = position.pos_name;

            var list_address            = _dbContext.address.Where(i => i.staff_id == staff_cur.sta_id).ToList();
            List <addressviewmodel> lst = new List <addressviewmodel>();

            foreach (address i in list_address)
            {
                addressviewmodel add = _mapper.Map <addressviewmodel>(i);
                add.ward_id     = _dbContext.ward.Where(t => t.Name.Contains(i.add_ward)).FirstOrDefault().Id;
                add.district_id = _dbContext.district.Where(t => t.Name.Contains(i.add_district)).FirstOrDefault().Id;
                add.province_id = _dbContext.province.Where(t => t.Name.Contains(i.add_province)).FirstOrDefault().Id;
                lst.Add(add);
            }
            res.list_address = lst;
            return(res);
        }
Beispiel #2
0
        public customerviewmodel GetInfor(int cu_id)
        {
            customerviewmodel res = new customerviewmodel();
            var customer_cur      = _dbContext.customers.Where(i => i.cu_id == cu_id).FirstOrDefault();
            var customerview      = _mapper.Map <customerviewmodel>(customer_cur);

            res = customerview;
            var sources       = _dbContext.sources.FirstOrDefault(x => x.src_id == customer_cur.source_id);
            var customergroup = _dbContext.customer_group.FirstOrDefault(x => x.cg_id == customer_cur.customer_group_id);

            res.source_name         = sources.src_name;
            res.customer_group_name = customergroup.cg_name;
            for (int j = 0; j < 2; j++)
            {
                if (j == customer_cur.cu_type)
                {
                    res.cu_type_name = EnumCustomer.cu_type[j];
                }
            }
            var list_address            = _dbContext.address.Where(i => i.customer_id == customer_cur.cu_id).ToList();
            List <addressviewmodel> lst = new List <addressviewmodel>();

            foreach (address i in list_address)
            {
                addressviewmodel add = _mapper.Map <addressviewmodel>(i);
                add.ward_id     = _dbContext.ward.Where(t => t.Name.Contains(i.add_ward)).FirstOrDefault().Id;
                add.district_id = _dbContext.district.Where(t => t.Name.Contains(i.add_district)).FirstOrDefault().Id;
                add.province_id = _dbContext.province.Where(t => t.Name.Contains(i.add_province)).FirstOrDefault().Id;
                lst.Add(add);
            }
            res.list_address = lst;
            return(res);
        }