public ActionResult <EstablishmentDTO> Create([FromBody] EstablishmentDTO establishmentDTO) { try { if (!ModelState.IsValid) { return(UnprocessableEntity(ModelState)); } establishmentDTO.ispartner = true; Establishment establishment = _mapper.Map <Establishment>(establishmentDTO); if (_establishmentAppService.CreateEntity(establishment) != null) { return(Created("/api/v1/establishment", HttpStatusCode.Created)); } return(BadRequest()); } catch (Exception ex) { return(BadRequest(ex)); } }
public ActionResult <EstablishmentDTO> Edit([FromBody] EstablishmentDTO establishmentDTO) { try { if (!ModelState.IsValid) { return(UnprocessableEntity(ModelState)); } Establishment establishment = _establishmentAppService.GetById((long)establishmentDTO.Id, this.User); if (establishment == null) { return(Forbid()); } establishment.CompanyName = establishmentDTO.CompanyName; establishment.Email = establishmentDTO.Email; establishment.Phone = establishmentDTO.Phone; establishment.Address = establishmentDTO.Address; establishment.Number = establishmentDTO.Number; establishment.Neighborhood = establishmentDTO.Neighborhood; _establishmentAppService.UpdateEntity(establishment); return(Ok(new ObjectResult(establishmentDTO))); } catch (Exception ex) { return(BadRequest(ex)); } }
public IHttpActionResult Add(EstablishmentDTO model) { var result = _establishmentManager.InsertEstablishment(model, 0); if (result == null) { return(BadRequest("Error adding establishment.")); } return(Ok(result)); }
public ActionResult <EstablishmentDTO> GetById(long id) { try { EstablishmentDTO establishmentDTO = _mapper.Map <EstablishmentDTO>(_establishmentAppService.GetById(id, this.User)); if (establishmentDTO == null) { return(NotFound()); } return(Ok(establishmentDTO)); } catch (Exception ex) { return(BadRequest(ex)); } }
private School GetEstablishment(EstablishmentDTO dto) { return(new School { Urn = new URN(dto.id), DfesNumber = ConvertId(dto.DFESNumber), SchoolName = dto.SchoolName, SchoolType = dto.SchoolType, CohortMeasures = new List <PerformanceMeasure>(), PerformanceMeasures = dto.performance .Select(p => new PerformanceMeasure { Name = p.Code, Value = p.CodeValue }) .ToList(), HeadTeacher = dto.HeadTitleCode + " " + dto.HeadFirstName + " " + dto.HeadLastName, HighestAge = dto.HighestAge, InstitutionTypeNumber = dto.InstitutionTypeNumber ?? 0, LowestAge = dto.LowestAge }); }
public Establishment InsertEstablishment(EstablishmentDTO dto, int user) { try { var establishment = new Establishment() { CreatedBy = user, CreatedDateTime = _establishment.GetCurrentDate(), Capacity = dto.Capacity, EstablishmentTypeID = dto.EstablishmentTypeID, MemberId = dto.MemberId, Name = dto.Name }; _establishment.Insert(establishment); _establishment.SaveChanges(); return(establishment); } catch (Exception e) { return(null); } }