public ActionResult <bool> UpdateEnterprise(int id, [FromBody] EnterpriseModel enterprise)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    foreach (var state in ModelState)
                    {
                        if (state.Key == nameof(enterprise.Name) && state.Value.Errors.Count > 0)
                        {
                            return(BadRequest(state.Value.Errors));
                        }
                    }
                }

                return(Ok(service.UpdateEnterprise(id, enterprise)));
            }
            catch (NotFoundException ex)
            {
                return(NotFound(ex.Message));
            }
            catch (Exception ex)
            {
                return(StatusCode(StatusCodes.Status500InternalServerError, ex.Message));
            }
        }
Example #2
0
        public async Task <IActionResult> Put(EnterpriseDTO Enterprise)
        {
            var isUpdated = await _enterpriseService.UpdateEnterprise(Enterprise);

            var response = new ApiResponse <bool>(isUpdated);

            return(Ok(response));
        }
        public async Task <IActionResult> Put(int id, EnterpriseDto enterpriseDto)
        {
            if (!User.Identity.IsAuthenticated)
            {
                throw new AuthenticationException();
            }
            var enterprise = _mapper.Map <Enterprise>(enterpriseDto);

            enterprise.Id = id;
            var result = await _enterpriseService.UpdateEnterprise(enterprise);

            var response = new ApiResponse <bool>(result);

            return(Ok(response));
        }
        public async Task <ActionResult> UpdateEnterprise(int id, Enterprise enterprise)
        {
            if (id != enterprise.Id)
            {
                return(BadRequest());
            }

            string result = await _service.UpdateEnterprise(enterprise);

            if (result == "Not Found")
            {
                return(NotFound());
            }
            return(Ok());
        }
Example #5
0
 public ActionResult Edit(EnterpriseModel enterprise)
 {
     if (enterprise.IsValid)
     {
         try
         {
             service.UpdateEnterprise(enterprise);
             return(RedirectToAction("Index"));
         }
         catch (Exception e)
         {
             ModelState.AddModelError("", e.Message);
         }
     }
     else
     {
         ModelState.AddModelError("", enterprise.Error);
     }
     return(View(enterprise));
 }
Example #6
0
        public ActionResult EditEnterprise(EnterpriseSocialSecurity model)
        {            //已存在判断
            bool isExists = _enterpriseService.IsExistsEnterprise(model.EnterpriseName, model.EnterpriseID);

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

            //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, model.EnterpriseID);
            }

            bool flag = _enterpriseService.UpdateEnterprise(model);

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

            TempData["Message"] = flag ? "保存成功" : "保存失败";
            return(RedirectToAction("GetEnterpriseList"));
        }