예제 #1
0
        public ActionResult AddEnterprise(EnterpriseSocialSecurity model)
        {
            //已存在判断
            bool isExists = _enterpriseService.IsExistsEnterprise(model.EnterpriseName);

            if (isExists)
            {
                ViewBag.Message = "企业名称已存在";
                return(AddEnterprise());
            }

            //ProvinceCode CityCode CountyCode
            string ProvinceName = string.Empty;
            string CityName     = string.Empty;
            string CountyName   = string.Empty;

            #region 将编码变成名称
            string sqlstr = "select * from Region where RegionCode = '{0}'";
            ProvinceName = DbHelper.QuerySingle <Region>(string.Format(sqlstr, model.ProvinceCode)).RegionName;
            CityName     = DbHelper.QuerySingle <Region>(string.Format(sqlstr, model.CityCode)).RegionName;
            CountyName   = DbHelper.QuerySingle <Region>(string.Format(sqlstr, model.CountyCode)).RegionName;
            #endregion

            model.EnterpriseArea = ProvinceName + "|" + CityName + "|" + CountyName;

            //更新其他签约企业  注:满足省份|城市和户口类型  默认的只有一个
            if (model.IsDefault)
            {
                _enterpriseService.UpdateEnterpriseDefault(ProvinceName + "|" + CityName, 0);
            }

            //添加
            bool flag = _enterpriseService.AddEnterprise(model);

            #region 记录日志
            LogService.WriteLogInfo(new Log {
                UserName = HttpContext.User.Identity.Name, Contents = string.Format("新增签约企业:{0}", model.EnterpriseName)
            });
            #endregion

            TempData["Message"] = flag ? "保存成功" : "保存失败";
            return(RedirectToAction("GetEnterpriseList"));
        }
        public async Task <IActionResult> AddEnterprise(EditEnterpriseParameters enterprise)
        {
            if (ModelState.IsValid)
            {
                var temp = await enterpriseService.AddEnterprise(enterprise);

                if (temp != null)
                {
                    return(Ok(temp));
                }
                else
                {
                    return(BadRequest(new { Message = "Something went wrong. Please, try again later." }));
                }
            }
            else
            {
                return(BadRequest(new { Message = "Invalid parameters supplied." }));
            }
        }