Esempio n. 1
0
        /// <summary>
        /// 获取编辑页面下拉列表
        /// </summary>
        /// <param name="context">数据库连接上下文对象</param>
        /// <returns></returns>
        public async Task <InformationEditViewModel> GetDropDownListAsync(InformationEditViewModel webModel, ApplicationDbContext context)
        {
            //Get Source Data
            var buildingList = await DormitoryRepository.GetBuildingList(context);

            var bunkList = await DormitoryRepository.GetBunkList(context);

            if (buildingList != null && buildingList.Any())
            {
                webModel.BuildingList = buildingList.Select(item => new BuildingDropDown
                {
                    Id   = item.Id.ToString(),
                    Name = item.Name
                }).ToList();
            }

            if (bunkList != null && bunkList.Any())
            {
                webModel.BunkList = bunkList.Select(item => new BunkDropDown
                {
                    Id    = item.Id.ToString(),
                    Name  = item.Name,
                    Count = item.Number
                }).ToList();
            }

            return(webModel);
        }
Esempio n. 2
0
        public async Task <IActionResult> EditInformation(InformationEditViewModel webModel)
        {
            if (ModelState.IsValid)
            {
                bool flag;
                if (string.IsNullOrEmpty(webModel.Id))
                {
                    //Add Dorm Information
                    flag = await _service.InsertInformationAsync(webModel, _context);
                }
                else
                {
                    //Update Dorm Information
                    flag = await _service.UpdateInformationAsync(webModel, _context);
                }

                return(Json(new
                {
                    success = flag,
                    msg = flag ? "宿舍信息编辑成功" : "宿舍信息编辑失败"
                }));
            }

            return(Json(new
            {
                success = false,
                msg = this.ModelState.Keys.SelectMany(key => this.ModelState[key].Errors).FirstOrDefault().ErrorMessage
            }));
        }
Esempio n. 3
0
        /// <summary>
        /// 更新寝室信息
        /// </summary>
        /// <param name="webModel">编辑页视图模型</param>
        /// <param name="context">数据库上下文对象</param>
        public static async void UpdateAsync(InformationEditViewModel webModel, ApplicationDbContext context)
        {
            var model = await context.Dorm.FirstOrDefaultAsync(i => i.Id == Convert.ToInt64(webModel.Id));

            if (model == null)
            {
                return;
            }

            UpdateModel(webModel, model);

            //Get Foreign Key Association Table Information
            //
            var building = await context.Building.AsNoTracking().Where(i => i.Id == Convert.ToInt64(webModel.BuildingId)).FirstOrDefaultAsync();

            var bunk = await context.Bunk.AsNoTracking().Where(i => i.Id == Convert.ToInt64(webModel.BunkId)).FirstOrDefaultAsync();

            //return error
            if (building == null || bunk == null)
            {
                return;
            }

            model.BuildingFK   = building.BuildingOID;
            model.BuildingId   = Convert.ToInt64(webModel.BuildingId);
            model.BuildingName = building.Name;
            model.Type         = building.Type;

            model.BunkFK   = bunk.BunkOID;
            model.BunkId   = Convert.ToInt64(webModel.BunkId);
            model.BunkName = bunk.Name;
        }
Esempio n. 4
0
        /// <summary>
        /// 新增寝室信息
        /// </summary>
        /// <param name="webModel">编辑页视图模型</param>
        /// <param name="context">数据库上下文对象</param>
        /// <returns></returns>
        public static async Task <Dorm> InsertAsync(InformationEditViewModel webModel, ApplicationDbContext context)
        {
            //Get Foreign Key Association Table Information
            //
            var building = await context.Building.AsNoTracking().Where(i => i.Id == Convert.ToInt64(webModel.BuildingId)).FirstOrDefaultAsync();

            var bunk = await context.Bunk.AsNoTracking().Where(i => i.Id == Convert.ToInt64(webModel.BunkId)).FirstOrDefaultAsync();

            //return error
            if (building == null || bunk == null)
            {
                return(new Dorm
                {
                    Id = -1
                });
            }

            Dorm model = InsertModel(webModel);

            model.BuildingFK   = building.BuildingOID;
            model.BuildingId   = Convert.ToInt64(webModel.BuildingId);
            model.BuildingName = building.Name;
            model.Type         = building.Type;

            model.BunkFK   = bunk.BunkOID;
            model.BunkId   = Convert.ToInt64(webModel.BunkId);
            model.BunkName = bunk.Name;

            await context.Dorm.AddAsync(model);

            return(model);
        }
Esempio n. 5
0
 /// <summary>
 /// Update Dorm Entity
 /// </summary>
 /// <param name="webModel"></param>
 /// <param name="model"></param>
 private static void UpdateModel(InformationEditViewModel webModel, Dorm model)
 {
     model.Count        = webModel.Count;
     model.Floor        = webModel.Floor;
     model.IsEnabled    = (int)webModel.IsEnabled == 1;
     model.Name         = webModel.Name;
     model.ModifiedOn   = DateTime.Now;
     model.ModifiedId   = CurrentUser.UserId;
     model.ModifiedBy   = CurrentUser.UserOID;
     model.ModifiedName = CurrentUser.UserName;
 }
Esempio n. 6
0
 /// <summary>
 /// Insert Dorm Entity
 /// </summary>
 /// <param name="webModel"></param>
 /// <returns></returns>
 private static Dorm InsertModel(InformationEditViewModel webModel)
 {
     return(new Dorm
     {
         Count = webModel.Count,
         CreatedId = CurrentUser.UserId,
         Floor = webModel.Floor,
         SelectedCount = 0,
         Name = webModel.Name,
         IsEnabled = (int)webModel.IsEnabled == 1,
         CreatedBy = CurrentUser.UserOID,
         CreatedName = CurrentUser.UserName
     });
 }
Esempio n. 7
0
        public async Task <IActionResult> EditInformation(string id)
        {
            InformationEditViewModel webModel = new InformationEditViewModel();

            if (!string.IsNullOrEmpty(id))
            {
                //编辑信息,加载宿舍相关信息
                webModel = await _service.GetInformationAsync(Convert.ToInt64(id), _context);
            }

            //加载下拉列表信息
            webModel = await _service.GetDropDownListAsync(webModel, _context);

            return(View(webModel));
        }
Esempio n. 8
0
        /// <summary>
        /// 更新宿舍信息
        /// </summary>
        /// <param name="webModel">编辑页视图Model</param>
        /// <param name="context">数据库连接上下文对象</param>
        /// <returns></returns>
        public async Task <bool> UpdateInformationAsync(InformationEditViewModel webModel, ApplicationDbContext context)
        {
            try
            {
                //Update Building Data
                DormitoryRepository.UpdateAsync(webModel, context);

                //Add Operate Information
                var operate = string.Format("修改宿舍信息,宿舍编号:{0}", webModel.Id);
                PSURepository.InsertRecordAsync("Dorm", "DormitoryDomain", "UpdateInformationAsync", operate, (short)PSURepository.OperateCode.Update, Convert.ToInt64(webModel.Id), context);

                var index = await context.SaveChangesAsync();

                return(index == 2);
            }
            catch (Exception ex)
            {
                _logger.LogError("更新宿舍失败:{0},\r\n内部错误信息:{1}", ex.Message, ex.InnerException.Message);
                return(false);
            }
        }
Esempio n. 9
0
        /// <summary>
        /// 获取宿舍信息
        /// </summary>
        /// <param name="id">宿舍编号</param>
        /// <param name="context">数据库连接上下文对象</param>
        /// <returns></returns>
        public async Task <InformationEditViewModel> GetInformationAsync(long id, ApplicationDbContext context)
        {
            var webModel = new InformationEditViewModel();

            try
            {
                var model = await DormitoryRepository.GetDormAsync(id, context);

                webModel.Id         = model.Id.ToString();
                webModel.BuildingId = model.BuildingId.ToString();
                webModel.BunkId     = model.BunkId.ToString();
                webModel.Count      = model.Count;
                webModel.Floor      = model.Floor;
                webModel.IsEnabled  = (Enable)(model.IsEnabled ? 1 : 0);
                webModel.Name       = model.Name;
            }
            catch (Exception ex)
            {
                _logger.LogError("获取宿舍数据失败:{0},\r\n内部错误信息:{1}", ex.Message, ex.InnerException.Message);
            }
            return(webModel);
        }
Esempio n. 10
0
        /// <summary>
        /// 新增宿舍信息
        /// </summary>
        /// <param name="webModel">编辑页视图Model</param>
        /// <param name="context">数据库连接上下文对象</param>
        /// <returns></returns>
        public async Task <bool> InsertInformationAsync(InformationEditViewModel webModel, ApplicationDbContext context)
        {
            try
            {
                //Add the Dorm Information Data
                var model = await DormitoryRepository.InsertAsync(webModel, context);

                if (model.Id == -1)
                {
                    return(false);
                }

                //Make the transaction commit
                var index = await context.SaveChangesAsync();

                return(index == 1);
            }
            catch (Exception ex)
            {
                _logger.LogError("创建宿舍楼失败:{0},\r\n内部错误详细信息:{1}", ex.Message, ex.InnerException.Message);
                return(false);
            }
        }