Exemple #1
0
        /// <summary>
        /// 根据区域编号获取区域信息
        /// </summary>
        /// <param name="areaID">区域编号</param>
        /// <returns></returns>
        public static SelectResult <AreaEditModel> GetAreaByID(int areaID)
        {
            SqlParameter para = new SqlParameter("@ID", SqlDbType.Int);

            para.Value = areaID;
            SqlParameter[] paras = { para };


            string sql = "SELECT * FROM Areas WHERE ID=@ID";
            List <AreaEditModel> list = ConvertToList <AreaEditModel> .Convert(MSSQLHelper.ExecuteDataTable(CommandType.Text, sql, paras));

            AreaEditModel data = null;
            string        msg  = string.Empty;

            if (list == null)
            {
                msg = PromptInformation.DBError;
            }
            else if (list.Count == 0)
            {
                msg = PromptInformation.NotExists;
            }
            else
            {
                data = list[0];
            }
            return(new SelectResult <AreaEditModel>()
            {
                DataResult = data,
                Message = msg
            });
        }
        public async Task EditAsync(AreaEditModel areaEdit)
        {
            var original = this.areasRepository
                           .All()
                           .First(x => x.Id == areaEdit.AreaId);

            original.Name = areaEdit.Name;
            await this.areasRepository.SaveChangesAsync();
        }
Exemple #3
0
 public ActionResult EditAreaInfo(AreaEditModel model)
 {
     if (ModelState.IsValid)
     {
         var result = AreaBLL.ModifyAreaInfo(model, base.UserIDForLog);
         base.DoLog(OperationTypeEnum.Edit, result, "AreaID:" + model.ID);
         return(Json(result));
     }
     else
     {
         return(PartialView("_EditAreaInfo", model));
     }
 }
Exemple #4
0
        /// <summary>
        /// 修改区域信息
        /// 根据区域编号修改区域名、区域描述
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public static OperationResult ModifyAreaInfo(AreaEditModel model, int UserID)
        {
            List <SqlParameter> paras = new List <SqlParameter>()
            {
                new SqlParameter("@areaName", SqlDbType.NVarChar, 20),
                new SqlParameter("@areaID", SqlDbType.Int),
                new SqlParameter("@description", SqlDbType.NVarChar, 50),
                new SqlParameter("@EditTime", SqlDbType.DateTime),
                new SqlParameter("@EditUserID", SqlDbType.Int)
            };

            paras[0].Value = model.AreaName.Trim();
            paras[1].Value = model.ID;


            if (string.IsNullOrWhiteSpace(model.Description))
            {
                paras[2].Value = DBNull.Value;
            }
            else
            {
                paras[2].Value = model.Description;
            }
            paras[3].Value = DateTime.Now;
            paras[4].Value = UserID;
            string sql    = "UPDATE Areas SET AreaName=@areaName,Description=@description,EditTime=@EditTime,EditUserID=@EditUserID WHERE ID=@areaID";
            int    result = MSSQLHelper.ExecuteNonQuery(CommandType.Text, sql, paras.ToArray());
            string msg    = string.Empty;

            switch (result)
            {
            case 1:
                msg = PromptInformation.OperationSuccess;
                break;

            case 0:
                msg = PromptInformation.NotExists;
                break;

            case -1:
                msg = PromptInformation.DBError;
                break;
            }
            return(new OperationResult()
            {
                Success = result > 0,
                Message = msg
            });
        }
        public async Task <IActionResult> Put(AreaEditModel areaEdit)
        {
            var response     = new Response();
            var exists       = this.areasService.Exists(x => x.Id == areaEdit.AreaId);
            var existsByName = this.areasService.Exists(x => x.Id != areaEdit.AreaId && x.Name == areaEdit.Name);

            if (!exists)
            {
                response.Message = "No such area!";
                return(this.NotFound(response));
            }

            if (!this.ModelState.IsValid || existsByName)
            {
                response.Message = "Invalid input!";
                return(this.BadRequest(response));
            }

            await this.areasService.EditAsync(areaEdit);

            response.Message = "Successfully edited area!";

            return(this.Ok(response));
        }
        public ActionResult _EditArea(AreaEditModel model)
        {
            bool flag = areaService.IsChildArea(model.ParentCode, model.AreaCode);

            if (flag)
            {
                return Json(new StatusMessageData(StatusMessageType.Error, "不能将地区的父地区设置为其子地区!"));
            }
            areaService.Update(model.AsArea());

            return Json(new StatusMessageData(StatusMessageType.Success, "更新成功!"));
        }
Exemple #7
0
        public async Task <IActionResult> Edit([Required][FromForm] int id, AreaEditModel areaEditModel)
        {
            if (ModelState.IsValid)
            {
                IDbContextTransaction transaction = null;
                try
                {
                    transaction = await lawyerDbContext.Database.BeginTransactionAsync();

                    Area area = await lawyerDbContext.Areas.FindAsync(id);

                    if (area == null)
                    {
                        throw new NullReferenceException("This area doesn't exist. ");
                    }

                    area.MeetingMinute = areaEditModel.MeetingMinute;

                    IEnumerable <Text> nameTextAllLanguage = await lawyerDbContext.Texts
                                                             .Where(m => m.Key == area.NameKey)
                                                             .ToListAsync();

                    IEnumerable <Text> descriptionTextAllLanguage = await lawyerDbContext.Texts
                                                                    .Where(m => m.Key == area.DescriptionKey)
                                                                    .ToListAsync();

                    //Update texts all language for properties
                    foreach (var item in areaEditModel.Areas)
                    {
                        Text name = nameTextAllLanguage.SingleOrDefault(m => m.LanguageId == item.LanguageId);
                        name.TextContent = item.Name;
                        Text description = descriptionTextAllLanguage.SingleOrDefault(m => m.LanguageId == item.LanguageId);
                        description.TextContent = item.Description;
                    }

                    await lawyerDbContext.SaveChangesAsync();

                    transaction.Commit();

                    return(RedirectToAction(nameof(Index)));
                }

                catch (NullReferenceException exp)
                {
                    ModelState.AddModelError("", exp.Message);
                }

                catch
                {
                    transaction.Rollback();

                    ModelState.AddModelError("", "Some error occured. Please try again.");
                }
                finally
                {
                    if (transaction != null)
                    {
                        transaction.Dispose();
                    }
                }
            }

            AreaViewModel areaViewModel = new AreaViewModel
            {
                Id        = id,
                Areas     = areaEditModel.Areas,
                Languages = await lawyerDbContext.Languages
                            .AsNoTracking()
                            .ToListAsync(),
                MeetingMinute = areaEditModel.MeetingMinute
            };

            return(View(areaViewModel));
        }