コード例 #1
0
        public ActionResult Put(Guid id, [FromBody] BasicInfoApiModel basicInfo)
        {
            try
            {
                ApiResponse serviceResponse = this._communityService.GetById(id);
                if (serviceResponse.IsSuccess() == false)
                {
                    return(new ObjectNotFoundResult(serviceResponse));
                }

                Community community = serviceResponse.GetData <Community>();
                _mapper.Map(basicInfo, community);
                serviceResponse = this._communityService.Update(id, community);

                if (serviceResponse.IsSuccess())
                {
                    return(new ObjectUpdatedResult(serviceResponse.Id.Value));
                }
                {
                    return(new ValidationErrorResult(serviceResponse));
                }
            }
            catch (Exception ex)
            {
                return(new UnknownErrorResult(ex, base._errorEnabled));
            }
        }
コード例 #2
0
        public CommunityApiModel MapGet(Community community, LocationElemensDto locationElementsDto, List <Section> sections)
        {
            BasicInfoApiModel        basicInfoApiModel         = new BasicInfoApiModel();
            AssociationApiModel      associationApiModel       = new AssociationApiModel();
            LocationApiModel         locationApiModel          = new LocationApiModel();
            SelectedLocationApiModel selectedLocationViewModel = new SelectedLocationApiModel();

            _mapper.Map(community, basicInfoApiModel);
            _mapper.Map(community.Association, associationApiModel);
            _mapper.Map(community.Location, locationApiModel);

            selectedLocationViewModel.Countries = Map(locationElementsDto.Countries);
            selectedLocationViewModel.States    = Map(locationElementsDto.States);
            selectedLocationViewModel.Cities    = Map(locationElementsDto.Cities);
            selectedLocationViewModel.Areas     = Map(locationElementsDto.Areas);
            selectedLocationViewModel.SubAreas  = Map(locationElementsDto.SubAreas);

            JObject jObject = new JObject();

            Map(jObject, sections);
            return(new CommunityApiModel()
            {
                BasicInfo = basicInfoApiModel,
                Association = associationApiModel,
                SelectedLocation = selectedLocationViewModel,
                Sections = jObject.ToObject <Dictionary <string, object> >()
            });
        }
コード例 #3
0
        public ActionResult Post([FromBody] BasicInfoApiModel basicInfo)
        {
            try
            {
                Community community = new Community();
                _mapper.Map(basicInfo, community);

                ApiResponse serviceResponse = this._communityService.Create(community);
                if (serviceResponse.IsSuccess())
                {
                    return(new ObjectCreatedResult("community", serviceResponse.Id.Value));
                }
                else
                {
                    return(new ValidationErrorResult(serviceResponse));
                }
            }
            catch (Exception ex)
            {
                return(new UnknownErrorResult(ex, base._errorEnabled));
            }
        }