Esempio n. 1
0
        public async Task <IActionResult> EditBunk(BunkEditViewModel webModel)
        {
            if (ModelState.IsValid)
            {
                bool flag;
                if (string.IsNullOrEmpty(webModel.Id))
                {
                    //Add Building
                    flag = await _service.InsertBunkAsync(webModel, _context);
                }
                else
                {
                    //Update Building
                    flag = await _service.UpdateBunkAsync(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. 2
0
        public async Task <IActionResult> EditBunk(string id)
        {
            BunkEditViewModel webModel = new BunkEditViewModel();

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

            return(View(webModel));
        }
Esempio n. 3
0
        /// <summary>
        /// 新增宿舍类型信息
        /// </summary>
        /// <param name="webModel">编辑页视图模型</param>
        /// <param name="context">数据库上下文对象</param>
        /// <returns></returns>
        public static async Task <Bunk> InsertAsync(BunkEditViewModel webModel, ApplicationDbContext context)
        {
            var model = new Bunk
            {
                IsEnabled   = (int)webModel.IsEnabled == 1,
                ImageSrc    = webModel.ImageSrc,
                Name        = webModel.Name,
                Number      = webModel.Number,
                Toward      = webModel.Toward.ToString(),
                CreatedId   = CurrentUser.UserId,
                CreatedBy   = CurrentUser.UserOID,
                CreatedName = CurrentUser.UserName
            };
            await context.Bunk.AddAsync(model);

            return(model);
        }
Esempio n. 4
0
        /// <summary>
        /// 新增宿舍类型信息
        /// </summary>
        /// <param name="webModel">编辑页视图Model</param>
        /// <param name="context">数据库连接上下文对象</param>
        /// <returns></returns>
        public async Task <bool> InsertBunkAsync(BunkEditViewModel webModel, ApplicationDbContext context)
        {
            try
            {
                //Add the Bunk Data
                var model = await DormitoryRepository.InsertAsync(webModel, context);

                //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);
            }
        }
Esempio n. 5
0
        /// <summary>
        /// 更新宿舍类型信息
        /// </summary>
        /// <param name="webModel">编辑页视图模型</param>
        /// <param name="context">数据库上下文对象</param>
        public static async void UpdateAsync(BunkEditViewModel webModel, ApplicationDbContext context)
        {
            var model = await context.Bunk.FirstOrDefaultAsync(i => i.Id == Convert.ToInt64(webModel.Id));

            if (model == null)
            {
                return;
            }

            model.IsEnabled    = (int)webModel.IsEnabled == 1;
            model.ImageSrc     = webModel.ImageSrc;
            model.Name         = webModel.Name;
            model.Number       = webModel.Number;
            model.Toward       = webModel.Toward.ToString();
            model.ModifiedOn   = DateTime.Now;
            model.ModifiedId   = CurrentUser.UserId;
            model.ModifiedBy   = CurrentUser.UserOID;
            model.ModifiedName = CurrentUser.UserName;
        }
Esempio n. 6
0
        /// <summary>
        /// 更新宿舍类型信息
        /// </summary>
        /// <param name="webModel">编辑页视图Model</param>
        /// <param name="context">数据库连接上下文对象</param>
        /// <returns></returns>
        public async Task <bool> UpdateBunkAsync(BunkEditViewModel webModel, ApplicationDbContext context)
        {
            try
            {
                //Update Bunk Data
                DormitoryRepository.UpdateAsync(webModel, context);

                //Add Operate Information
                var operate = string.Format("修改宿舍类型信息,宿舍类型编号:{0}", webModel.Id);
                PSURepository.InsertRecordAsync("Bunk", "DormitoryDomain", "UpdateBunkAsync", 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. 7
0
        /// <summary>
        /// 获取宿舍类型信息
        /// </summary>
        /// <param name="id">宿舍类型编号</param>
        /// <param name="context">数据库连接上下文对象</param>
        /// <returns></returns>
        public async Task <BunkEditViewModel> GetBunkAsync(long id, ApplicationDbContext context)
        {
            var webModel = new BunkEditViewModel();

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

                webModel.Id        = model.Id.ToString();
                webModel.IsEnabled = (Enable)(model.IsEnabled ? 1 : 0);
                webModel.Name      = model.Name;
                webModel.ImageSrc  = model.ImageSrc;
                webModel.Toward    = (BunkToward)Enum.Parse(typeof(BunkToward), model.Toward);
                webModel.Number    = model.Number;
            }
            catch (Exception ex)
            {
                _logger.LogError("获取宿舍类型数据失败:{0},\r\n内部错误信息:{1}", ex.Message, ex.InnerException.Message);
            }
            return(webModel);
        }