Example #1
0
        public bool Update(long Id, CyclesBE Be)
        {
            try
            {
                if (Be == null)
                {
                    throw new ApiBusinessException(007, "La entidad no está completa", System.Net.HttpStatusCode.NotFound, "Http");
                }

                Cycles entity = _unitOfWork.CyclesRepository.GetAllByFilters(t => t.name.ToLower() == Be.name.ToLower(), null).FirstOrDefault();
                if (entity != null && entity.idcycle != Id)
                {
                    throw new ApiBusinessException(005, "Ya existe un ciclo con ese nombre, por favor elija otro nombre", System.Net.HttpStatusCode.BadRequest, "Http");
                }


                Mapper.Initialize(cfg =>
                {
                    cfg.CreateMap <CyclesBE, Cycles>();
                });
                Cycles myentity = Mapper.Map <CyclesBE, Cycles>(Be);
                _unitOfWork.CyclesRepository.Update(myentity, new List <String> {
                    "name", "state"
                });
                _unitOfWork.Commit();
                return(true);
            }


            catch (Exception ex)
            {
                throw HandlerExceptions.GetInstance().RunCustomExceptions(ex);
            }
        }
Example #2
0
        public CyclesBE GetById(long Id)
        {
            try
            {
                Expression <Func <Cycles, Boolean> > predicate = u => u.idcycle == Id;
                Cycles entity = _unitOfWork.CyclesRepository.GetOneByFilters(predicate, null);

                if (entity == null)
                {
                    throw new ApiBusinessException(006, "No existe el ciclo", System.Net.HttpStatusCode.NotFound, "Http");
                }

                Mapper.Initialize(cfg => {
                    cfg.CreateMap <Cycles, CyclesBE>();
                });
                CyclesBE be = Mapper.Map <Cycles, CyclesBE>(entity);
                return(be);
            }


            catch (Exception ex)
            {
                throw HandlerExceptions.GetInstance().RunCustomExceptions(ex);
            }
        }
Example #3
0
 //[ClaimsAuthorizationAttribute(ClaimType = "Gestionar servicios")]
 public async Task <IHttpActionResult> PostCycles(CyclesBE Be)
 {
     if (!ModelState.IsValid)
     {
         return(BadRequest(ModelState));
     }
     _services.Create(Be);
     return(Created(new Uri(Url.Link("DefaultApi", new { Id = Be.idcycle })), Be));
 }
Example #4
0
 public async Task <IHttpActionResult> PutChallenge(int id, CyclesBE Be)
 {
     if (!ModelState.IsValid)
     {
         return(BadRequest(ModelState));
     }
     _services.Update(id, Be);
     return(Ok());
 }
Example #5
0
        public async Task <IHttpActionResult> Get(int id)
        {
            CyclesBE Be = _services.GetById(id);

            if (Be == null)
            {
                return(NotFound());
            }
            return(Ok(Be));
        }
Example #6
0
        public long Create(CyclesBE Be)
        {
            try
            {
                if (_unitOfWork.CyclesRepository.GetOneByFilters(t => t.name == Be.name, null) != null)
                {
                    throw new ApiBusinessException(005, "Ya existe un ciclo con ese nombre, por favor elija otro nombre", System.Net.HttpStatusCode.BadRequest, "Http");
                }

                Mapper.Initialize(cfg => {
                    cfg.CreateMap <CyclesBE, Cycles>();
                });
                Cycles entity = Mapper.Map <CyclesBE, Cycles>(Be);
                _unitOfWork.CyclesRepository.Insert(entity);
                _unitOfWork.Commit();
                return(entity.idcycle);
            }
            catch (Exception ex)
            {
                throw HandlerExceptions.GetInstance().RunCustomExceptions(ex);
            }
        }