コード例 #1
0
        public IHttpActionResult Get()
        {
            var companies = _companyRepo.Get();

            if (companies == null)
            {
                return(NotFound());
            }

            return(Ok(companies));
        }
コード例 #2
0
        public int EditCompanyDetail(EditCompanyDetailViewModel model)
        {
            //var userId = contextUser.Claims.First(x => x.Type == ClaimTypes.NameIdentifier).Value;
            var user = _userService.GetUser();

            if (!_sectorService.isSectorValid(model.SectorId))
            {
                return(0);
            }
            CompanyDetail companyDetail = _companyDetailRepository.Get(x => x.UserId == user.UserId);

            if (companyDetail == null)
            {
                companyDetail = new CompanyDetail();
                _companyDetailRepository.Add(companyDetail);
                companyDetail.CreateDate = DateTime.Now;
            }
            else
            {
                companyDetail.UpdateDate = DateTime.Now;
            }
            if (model.ImagePath != null)
            {
                companyDetail.ImageUrl = model.ImagePath;
            }

            companyDetail.UserId            = user.UserId;
            companyDetail.SectorId          = model.SectorId;
            companyDetail.CompanyName       = model.CompanyName;
            companyDetail.FoundationYear    = model.FoundationYear;
            companyDetail.Address           = model.Address;
            companyDetail.NumberOfEmployees = model.NumberOfEmployees;
            companyDetail.WebSite           = model.WebSite;
            companyDetail.About             = model.About;
            //companyDetail.ImageUrl = model.ImageUrl;//?

            try
            {
                _companyDetailRepository.SaveChanges();
                return(companyDetail.Id);
            }
            catch (Exception ex)
            {
                var errorMessage = ex.Message;
                throw;
            }
        }