public async Task <IHttpActionResult> Put(int id, [FromBody] CommunityViewModel model) { try { if (model == null) { return(BadRequest()); } var db = CommunityMapper.Map(model); var result = await _communityService.UpdateAsync(db); if (result.Status == ActionStatus.Updated) { return(Ok(CommunityMapper.Map(result.Entity))); } else if (result.Status == ActionStatus.NotFound) { return(NotFound()); } return(BadRequest()); } catch (Exception) { return(InternalServerError()); } }
public async Task <IHttpActionResult> Post(CommunityViewModel model) { try { if (model == null) { return(BadRequest()); } var user = CommunityMapper.Map(model); var userUpdate = await this._communityService.InserAsync(user); if (userUpdate.Status == ActionStatus.Created) { return(Created(Request.RequestUri + "/" + userUpdate.Entity.Id , CommunityMapper.Map(userUpdate.Entity))); } return(BadRequest()); } catch (Exception) { return(InternalServerError()); } }
public override void OnActionExecuting() { _locationService = CreateService <LocationService>(); _associationService = CreateService <AssociationService>(); _communityService = CreateService <BL.CommunityService>(); _sectionService = CreateService <SectionService>(); _contactService = CreateService <ContactService>(); _attachmentService = CreateService <AttachmentService>(); _communityMapper = new CommunityMapper(this._mapper); }
public async Task <IHttpActionResult> Get(int id) { try { var data = await this._communityService.GetByIdAsync(id); if (data == null) { return(NotFound()); } return(Ok(CommunityMapper.Map(data))); } catch (Exception ex) { return(InternalServerError()); } }
public static async Task <CommunityCreated> Create(CreateCommunityRequest community) { if (community == null) { throw new AppArgumentException(nameof(community)); } if (string.IsNullOrWhiteSpace(community.Name)) { throw new AppArgumentException(nameof(community.Name)); } await CheckUserExists(community.UserId); var entity = Entities.Community.From(community.UserId.Value, community.Name); var created = await Context.CommunityGateway.Create(entity); return(CommunityMapper.CreateInsertedFrom(created)); }
public async Task <IHttpActionResult> Patch(PatchCommunityViewModel model) { try { if (model == null) { return(BadRequest()); } var db = await _communityService.GetByIdAsync(model.Id); if (db == null) { return(NotFound()); } var viewModel = CommunityMapper.Map(db); model.Model.ApplyTo(viewModel); var result = await _communityService.UpdateAsync(CommunityMapper.Map(viewModel, db)); if (result.Status == ActionStatus.Updated) { var returnMapper = CommunityMapper.Map(result.Entity); return(Ok(returnMapper)); } return(BadRequest()); } catch (Exception) { return(InternalServerError()); } }
public CommunityPerson AddPersonToCommunity(NameParam name, DateTime dateOfBirth) { Util.RequireNonNull(name, "name"); Util.RequireNonNull(dateOfBirth, "dateOfBirth"); var method = new Eu.Xroad.UsFolkV3.Producer.AddPersonToCommunityByNameAndDateOfBirth() { request = Mapper.Mapper.NameAndDateOfBirthParam(name, dateOfBirth) }; var request = new Eu.Xroad.UsFolkV3.Producer.AddPersonToCommunityByNameAndDateOfBirthRequest() { client = clientHeader, service = ServiceHeader(method.GetType()), userId = userIdHeader, id = IdHeader(), issue = issueHeader, protocolVersion = protocolVersionHeader, AddPersonToCommunityByNameAndDateOfBirth = method }; return(Call( () => webService.AddPersonToCommunityByNameAndDateOfBirth(request), r => CommunityMapper.Map(r.AddPersonToCommunityByNameAndDateOfBirthResponse) )); }
public CommunityPerson AddPersonToCommunity(NameParam name, AddressParam address) { Util.RequireNonNull(name, "name"); Util.RequireNonNull(address, "address"); var method = new Eu.Xroad.UsFolkV3.Producer.AddPersonToCommunityByNameAndAddress() { request = Mapper.Mapper.NameAndAddressParam(name, address) }; var request = new Eu.Xroad.UsFolkV3.Producer.AddPersonToCommunityByNameAndAddressRequest() { client = clientHeader, service = ServiceHeader(method.GetType()), userId = userIdHeader, id = IdHeader(), issue = issueHeader, protocolVersion = protocolVersionHeader, AddPersonToCommunityByNameAndAddress = method }; return(Call( () => webService.AddPersonToCommunityByNameAndAddress(request), (r) => CommunityMapper.Map(r.AddPersonToCommunityByNameAndAddressResponse) )); }
public async Task <IHttpActionResult> Get(string sort = "id", string fields = null, int page = 1, int pageSize = MaxPageSize) { try { //Ejemplo : /api/Communitys?fields=name' //Ejemplo : /api/Communitys?fields=name%2Cid' (se pasan name y id) //Ejemplo : /api/Communitys?fields=tags' (Propiedad completa de tag) var users = await this._communityService.GetAllAsync(); List <string> lstOfFields = new List <string>(); if (fields != null) { lstOfFields = fields.ToLower().Split(',').ToList(); } // Limito el maximo if (pageSize > MaxPageSize) { pageSize = MaxPageSize; } // calculo paginas var totalCount = users.Count(); var totalPages = (int)Math.Ceiling((double)totalCount / pageSize); var urlHelper = new UrlHelper(Request); var prevLink = page > 1 ? urlHelper.Link("CommunitysList", new { page = page - 1, pageSize = pageSize, sort = sort, fields = fields }) : ""; var nextLink = page < totalPages?urlHelper.Link("CommunitysList", new { page = page + 1, pageSize = pageSize, sort = sort, fields = fields }) : ""; var paginationHeader = new { currentPage = page, pageSize = pageSize, totalCount = totalCount, totalPages = totalPages, previousPageLink = prevLink, nextPageLink = nextLink }; HttpContext.Current.Response.Headers.Add("X-Pagination", Newtonsoft.Json.JsonConvert.SerializeObject(paginationHeader)); return(Ok(users .ApplySort(sort) .Skip(pageSize * (page - 1)) .Take(pageSize) .ToList() .Select(x => CommunityMapper.MapObject(CommunityMapper.Map(x), lstOfFields)))); } catch (Exception) { return(InternalServerError()); } }