public bool Update(long Id, CareersBE Be) { try { if (Be == null) { throw new ApiBusinessException(007, "La entidad no está completa.", System.Net.HttpStatusCode.NotFound, "Http"); } Careers entity = _unitOfWork.CareersRepository.GetAllByFilters(t => t.name.ToLower() == Be.name.ToLower(), null).FirstOrDefault(); if (entity != null && entity.idcareers != Id) { throw new ApiBusinessException(005, "Ya existe una carrera con ese nombre, por favor elija otro nombre.", System.Net.HttpStatusCode.BadRequest, "Http"); } Mapper.Initialize(cfg => { cfg.CreateMap <CareersBE, Careers>(); }); Careers myentity = Mapper.Map <CareersBE, Careers>(Be); _unitOfWork.CareersRepository.Update(myentity, new List <String> { "name", "state" }); _unitOfWork.Commit(); return(true); } catch (Exception ex) { throw HandlerExceptions.GetInstance().RunCustomExceptions(ex); } }
public CareersBE GetById(long Id) { try { Expression <Func <Careers, Boolean> > predicate = u => u.idcareers == Id; Careers entity = _unitOfWork.CareersRepository.GetOneByFilters(predicate, null); if (entity == null) { throw new ApiBusinessException(006, "No existe la carrera.", System.Net.HttpStatusCode.NotFound, "Http"); } Mapper.Initialize(cfg => { cfg.CreateMap <Careers, CareersBE>(); }); CareersBE be = Mapper.Map <Careers, CareersBE>(entity); return(be); } catch (Exception ex) { throw HandlerExceptions.GetInstance().RunCustomExceptions(ex); } }
//[ClaimsAuthorizationAttribute(ClaimType = "Gestionar servicios")] public async Task <IHttpActionResult> PostCareers(CareersBE Be) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } _services.Create(Be); return(Created(new Uri(Url.Link("DefaultApi", new { Id = Be.idcareers })), Be)); }
public async Task <IHttpActionResult> PutChallenge(int id, CareersBE Be) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } _services.Update(id, Be); return(Ok()); }
public async Task <IHttpActionResult> Get(int id) { CareersBE Be = _services.GetById(id); if (Be == null) { return(NotFound()); } return(Ok(Be)); }
public long Create(CareersBE Be) { try { if (_unitOfWork.CareersRepository.GetOneByFilters(t => t.name == Be.name, null) != null) { throw new ApiBusinessException(005, "Ya existe una carrera con ese nombre, por favor elija otro nombre.", System.Net.HttpStatusCode.BadRequest, "Http"); } Be.state = (Int32)StatesEnum.Valid; Mapper.Initialize(cfg => { cfg.CreateMap <CareersBE, Careers>(); }); Careers entity = Mapper.Map <CareersBE, Careers>(Be); _unitOfWork.CareersRepository.Insert(entity); _unitOfWork.Commit(); return(entity.idcareers); } catch (Exception ex) { throw HandlerExceptions.GetInstance().RunCustomExceptions(ex); } }