public async Task <IActionResult> UpdateCompanyAsync(CompanyUpdateDto com, Guid id)
        {
            if (string.IsNullOrEmpty(com.Name) && string.IsNullOrEmpty(com.ImagePath))
            {
                return(BadRequest("Fill all fields"));
            }
            var company = await _companiesService.GetByIdAsync(id);

            if (company == null)
            {
                return(BadRequest("Company with id " + id + " doesn't exist"));
            }
            try
            {
                if (!string.IsNullOrEmpty(com.Name))
                {
                    company.Name = com.Name;
                }
                if (!string.IsNullOrEmpty(com.ImagePath))
                {
                    company.ImagePath = com.ImagePath;
                }
                await _companiesService.UpdateAsync(company);

                return(Ok("Company with id " + id + " updated"));
            }
            catch
            {
                return(this.ServerError("Failed to update company with id " + id));
            }
        }
예제 #2
0
        public async Task <IActionResult> PatchCompany(Guid companyId, JsonPatchDocument <CompanyUpdateDto> patchDocument)
        {
            var companyEntity = await _companyRepository.GetCompanyAsync(companyId);

            if (companyEntity == null)
            {
                var companyUpdateDto = new CompanyUpdateDto();
                patchDocument.ApplyTo(companyUpdateDto, ModelState);
                if (!TryValidateModel(patchDocument))
                {
                    return(ValidationProblem(ModelState));
                }
                companyEntity    = _mapper.Map <Company>(companyUpdateDto);
                companyEntity.Id = companyId;
                _companyRepository.AddCompany(companyEntity);
                await _companyRepository.SaveAsync();

                var returnDto = _mapper.Map <CompanyDto>(companyEntity);
                return(CreatedAtRoute(nameof(GetCompany), new { companyId = returnDto.Id }, returnDto));
            }
            var dtoPatch = _mapper.Map <CompanyUpdateDto>(companyEntity);

            patchDocument.ApplyTo(dtoPatch, ModelState);
            if (!TryValidateModel(dtoPatch))
            {
                return(ValidationProblem(ModelState));
            }
            _mapper.Map(dtoPatch, companyEntity);
            _companyRepository.UpdateCompany(companyEntity);
            await _companyRepository.SaveAsync();

            return(NoContent());
        }
예제 #3
0
        public async Task <IActionResult> CreateCompany(Guid companyId, [FromBody] CompanyUpdateDto company)
        {
            //if (!await _companyRepository.CompanyExistAsync(companyId)) return NotFound();
            if (company == null)
            {
                return(NotFound());
            }
            var CompanyEntity = await _companyRepository.GetCompaniesAsync(companyId);

            //如果有这个数据就执行下面的更新,没有就走if里的添加
            if (CompanyEntity == null)
            {
                var companyAddDtoEntity = _mapper.Map <Company>(company);

                _companyRepository.AddCompany(companyId, companyAddDtoEntity);
                await _companyRepository.SaveAsync();

                var companyAddDto = _mapper.Map <CompanyDto>(companyAddDtoEntity);
                return(CreatedAtRoute(nameof(GetCompany), routeValues: new { companyId = companyId }, value: companyAddDto));
            }
            _mapper.Map(company, CompanyEntity);


            _companyRepository.UpdateCompany(CompanyEntity);
            await _companyRepository.SaveAsync();

            //更新后展示新的数据
            var companyDto = _mapper.Map <CompanyDto>(CompanyEntity);

            return(CreatedAtRoute(nameof(GetCompany), routeValues: new { companyId = companyId }, value: companyDto));
            //也可以啥都不展示,返回的是204
            //return NoContent();
        }
예제 #4
0
        public IActionResult UpdateCompany(int id, [FromBody] CompanyUpdateDto companyDto)
        {
            if (companyDto is null || id != companyDto?.Id)
            {
                return(BadRequest());
            }
            if (!_companyRepository.Exists(c => c.Id == id))
            {
                ModelState.AddModelError("", "Company doesn't exist in the database");
                return(StatusCode(500, ModelState));
            }

            Company company = _mapper.Map <Company>(companyDto);

            _companyRepository.Update(company);
            if (_companyRepository.Save() > 0)
            {
                return(NoContent());
            }
            else
            {
                ModelState.AddModelError("", "Something went wrong updating the company");
                return(StatusCode(500, ModelState));
            }
        }
        public async Task CanUpdateCompany()
        {
            var companyToUpdate = new CompanyUpdateDto
            {
                CompanyId = 1, Name = "Test Company"
            };
            var updatedCompany = await _httpClientHelper.PutAsync <CompanyUpdateDto, CompanyDto>(_baseUrl + "update", companyToUpdate).ConfigureAwait(false);

            Assert.Equal("Test Company", updatedCompany.Name);
        }
예제 #6
0
        public async Task <IResult> Update(CompanyUpdateDto companyUpdateDto, string modifieldByName)
        {
            var company = _mapper.Map <Company>(companyUpdateDto);

            company.ModifiedByName = modifieldByName;
            await _unitOfWork.Companies.UpdateAsync(company);

            await _unitOfWork.SaveAsync();

            return(new Result(ResultStatus.Success, $"{companyUpdateDto} adlı şirket basarılı bir şekilde güncellenmiştir..."));
        }
예제 #7
0
        public ActionResult <CompanyCreateDto> UpdateCompany(Guid id, CompanyUpdateDto companyUpdateDto)
        {
            var companyModelFromRepo = _repository.GetCompanyById(id);

            if (companyModelFromRepo != null)
            {
                //Dbcontext tracks changes mapped with the DTO class
                _mapper.Map(companyUpdateDto, companyModelFromRepo);

                _repository.UpdateCompany(companyModelFromRepo);
                _repository.SaveChanges();

                return(NoContent());
            }
            return(NotFound());
        }
        public async Task <IActionResult> UpdateAsync([FromBody] CompanyUpdateDto company, ApiVersion version)
        {
            Logger.LogDebug(nameof(UpdateAsync));
            var repoCompany = await _repositoryFactory.CompanyRepository.GetCompanyAsync(company.CompanyId).ConfigureAwait(false);

            if (repoCompany == null)
            {
                return(NotFound(new { message = "The company was not found" }));
            }
            repoCompany.Name = company.Name;
            await _repositoryFactory.CompanyRepository.UpdateAsync(repoCompany).ConfigureAwait(false);

            await _repositoryFactory.SaveAsync().ConfigureAwait(false);

            var result = _companyToDtoConverter.Convert(repoCompany);

            return(Ok(result));
        }
예제 #9
0
        public CompanyUpdateDto GetForEdit(int id)
        {
            CompanyUpdateDto companyDto = null;

            try
            {
                var company = _unitOfWork.GenericRepository <Company>().GetById(id);
                if (company != null)
                {
                    companyDto = Mapper.Map <Company, CompanyUpdateDto>(company);
                }
            }
            catch (Exception ex)
            {
                Tracing.SaveException(ex);
            }

            return(companyDto);
        }
예제 #10
0
        public CompanyDto Update(CompanyUpdateDto dto)
        {
            CompanyDto companyDto = null;

            try
            {
                var company = _unitOfWork.GenericRepository <Company>().GetById(dto.Id);

                _unitOfWork.CreateTransaction();

                foreach (var companyCashDto in dto.CompanyCashes)
                {
                    if (companyCashDto.Id == null || companyCashDto.Id == 0)
                    {
                        _companyCashAppService.Insert(companyCashDto);
                    }
                    else
                    {
                        _companyCashAppService.Update(companyCashDto);
                    }
                }

                CheckForDelete(dto.CompanyCountries, company.CompanyCountries);
                CheckForAdd(dto.CompanyCountries);

                company.ModifiedBy = _appSession.GetUserName();
                company.Name       = dto.Name;

                _unitOfWork.GenericRepository <Company>().Update(company);
                _unitOfWork.Save();

                _unitOfWork.Commit();
                _unitOfWork.GenericRepository <Company>().RefershEntity(company);
                companyDto = Mapper.Map <Company, CompanyDto>(company);
            }
            catch (Exception ex)
            {
                Tracing.SaveException(ex);
                _unitOfWork.Rollback();
            }
            return(companyDto);
        }
예제 #11
0
        public IActionResult Update([FromBody] CompanyUpdateDto parm)
        {
            if (_companyService.Any(m => m.CompanyNo == parm.CompanyNo && m.ID != parm.ID))
            {
                return(toResponse(StatusCodeType.Error, $"更新公司编码 {parm.CompanyNo} 已存在,不能重复!"));
            }

            var userSession = _tokenManager.GetSessionInfo();

            return(toResponse(_companyService.Update(m => m.ID == parm.ID, m => new Base_Company()
            {
                CompanyNo = parm.CompanyNo,
                CompanyName = parm.CompanyName,
                Enable = parm.Enable,
                Remark = parm.Remark,
                UpdateID = userSession.UserID,
                UpdateName = userSession.UserName,
                UpdateTime = DateTime.Now
            })));
        }
예제 #12
0
        public async Task <IActionResult> UpdateCompany(Guid companyId, CompanyUpdateDto companyUpdateDto)
        {
            if (!await _companyRepository.CompanyExistsAsync(companyId))
            {
                var companyAdd = _mapper.Map <Company>(companyUpdateDto);
                companyAdd.Id = companyId;
                _companyRepository.AddCompany(companyAdd);
                bool result = await _companyRepository.SaveAsync();

                var returnDto = _mapper.Map <CompanyDto>(companyAdd);
                return(CreatedAtRoute(nameof(GetCompany), new { companyId = returnDto.Id }, returnDto));
            }
            var company = await _companyRepository.GetCompanyAsync(companyId);

            _mapper.Map(companyUpdateDto, company);
            _companyRepository.UpdateCompany(company);
            await _companyRepository.SaveAsync();

            return(NoContent());
        }
예제 #13
0
 public ApiResultDto UpdateCompany([FromBody] CompanyUpdateDto account)
 {
     return(Result(_bll.Update(account, GetToken())));
 }
예제 #14
0
        /// <summary>
        /// 保存并关闭 修改客户的点击事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void save_close_Click(object sender, EventArgs e)
        {
            var param = new CompanyUpdateDto();

            param.general_update = AssembleModel <CompanyUpdateDto.General_Update>();
            // param.general_update.is_active = (sbyte)(isactive.Checked ? 1 : 0);
            param.general_update.is_optout_survey = (sbyte)(is_optoutSurvey.Checked ? 1 : 0);
            param.general_update.taxExempt        = Tax_Exempt.Checked;
            param.additional_info    = AssembleModel <CompanyUpdateDto.Additional_Info>();
            param.alerts             = AssembleModel <CompanyUpdateDto.Alerts>();
            param.site_configuration = AssembleModel <CompanyUpdateDto.Site_Configuration>();


            if (company_udfList != null && company_udfList.Count > 0)                      // 首先判断是否有自定义信息
            {
                var list = new List <UserDefinedFieldValue>();
                foreach (var udf in company_udfList)                            // 循环添加
                {
                    var new_udf = new UserDefinedFieldValue()
                    {
                        id    = udf.id,
                        value = Request.Form[udf.id.ToString()] == "" ? null : Request.Form[udf.id.ToString()],
                    };
                    list.Add(new_udf);
                }
                param.general_update.udf = list;
            }

            if (site_udfList != null && site_udfList.Count > 0)                      // 首先判断是否有自定义信息
            {
                var list = new List <UserDefinedFieldValue>();
                foreach (var udf in site_udfValueList)                            // 循环添加
                {
                    var new_udf = new UserDefinedFieldValue()
                    {
                        id    = udf.id,
                        value = Request.Form[udf.id.ToString()] == "" ? null : Request.Form[udf.id.ToString()],
                    };
                    list.Add(new_udf);
                }
                param.site_configuration.udf = list;
            }

            //try
            //{out string updateLocationContact,out string updateFaxPhoneContact
            string updateLocationContact = "";
            string updateFaxPhoneContact = "";
            var    result = new CompanyBLL().Update(param, GetLoginUserId(), out updateLocationContact, out updateFaxPhoneContact);

            if (result == ERROR_CODE.PARAMS_ERROR)   // 必填参数丢失,重写
            {
                ClientScript.RegisterStartupScript(this.GetType(), "提示信息", "<script>alert('必填参数丢失,请重新填写');</script>");
            }
            else if (result == ERROR_CODE.CRM_ACCOUNT_NAME_EXIST)      // 用户名称已经存在,重新填写用户名称
            {
                ClientScript.RegisterStartupScript(this.GetType(), "提示信息", "<script>alert('客户已经存在');</script>");
            }
            else if (result == ERROR_CODE.PHONE_OCCUPY)      // 用户名称已经存在,重新填写用户名称
            {
                ClientScript.RegisterStartupScript(this.GetType(), "提示信息", "<script>alert('电话已有人在使用,请更换电话。');</script>");
                //Response.Write("<script>alert('电话已有人在使用,请更换电话。'); </script>");
            }
            else if (result == ERROR_CODE.USER_NOT_FIND)               // 用户丢失
            {
                Response.Write("<script>alert('查询不到用户,请重新登陆');</script>");
                Response.Redirect("../Login.aspx");
            }
            else if (result == ERROR_CODE.SUCCESS)                    // 修改用户成功
            {
                if (updateLocationContact == "" && updateFaxPhoneContact == "")
                {
                    Response.Write("<script>alert('修改客户成功!');window.close();self.opener.location.reload();</script>");  //  关闭添加页面的同时,刷新父页面
                }
                else
                {
                    Response.Write("<script>alert('修改客户成功!');window.open('UpdateContact.aspx?account_id=" + param.general_update.id + "&updateLocationContact=" + updateLocationContact + "&updateFaxPhoneContact=" + updateFaxPhoneContact + "','" + (int)EMT.DoneNOW.DTO.OpenWindow.OpportunityAdd + "','left= 200, top = 200, width = 960, height = 750', false);window.close();</script>");  //
                    //Response.Redirect("UpdateContact.aspx?account_id=" + param.general_update.id + "&updateLocationContact=" + updateLocationContact + "&updateFaxPhoneContact=" + updateFaxPhoneContact);
                }
            }
        }