Ejemplo n.º 1
0
        /// <summary>
        /// 获取寝室信息
        /// </summary>
        /// <param name="context">数据库连接上下文对象</param>
        /// <returns></returns>
        public async Task <DormitoryViewModel> GetDormitoryAsync(ApplicationDbContext context)
        {
            DormitoryViewModel webModel = new DormitoryViewModel();

            try
            {
                //Source Data List
                var list = await RegisterRepository.GetDormitoryListAsync(context);

                //Return Data List
                var dataList = new List <InformationData>();

                if (list != null && list.Any())
                {
                    foreach (var item in list)
                    {
                        var model = new InformationData
                        {
                            Id            = item.Id.ToString(),
                            Name          = item.Name,
                            BuildingName  = item.BuildingName,
                            Count         = item.Count,
                            Floor         = item.Floor,
                            SelectedCount = item.SelectedCount,
                            Type          = item.BunkName,
                        };
                        dataList.Add(model);
                    }
                }
                webModel.InformationList = dataList;
                var dorm = await RegisterRepository.GetDormitoryAsync(context);

                webModel.IsChosen = dorm != null;

                if (dorm != null)
                {
                    webModel.DormitoryInfo = new DormitoryInfo
                    {
                        BuildingName = dorm.BuildingName,
                        Floor        = (short)dorm.Floor,
                        Id           = dorm.Id.ToString(),
                        Name         = dorm.DormName,
                        Type         = dorm.BunkType,
                        DateTime     = dorm.DateTime.ToString("yyyy-MM-dd HH:mm:ss")
                    };
                }
            }
            catch (Exception ex)
            {
                _logger.LogError("获取物品信息列表失败:{0},\r\n内部错误信息:{1}", ex.Message, ex.InnerException.Message);
            }
            return(webModel);
        }