Пример #1
0
        public async Task <ActionResult <CampModels> > Post(CampModels model)
        {
            try
            {
                var monikerExits = await _campRepository.GetCampAsync(model.Moniker);

                if (monikerExits != null)
                {
                    return(BadRequest("Moniker da ton tai"));
                }

                var camp = _mapper.Map <Camp>(model);
                _campRepository.Add(camp);

                if (await _campRepository.SaveChangesAsync())
                {
                    return(Created($"/api/camps/{model.Moniker}", _mapper.Map <CampModels>(camp)));
                }
            }
            catch (Exception)
            {
                return(this.StatusCode(500, "Database Failure"));
            }

            return(BadRequest());
        }
Пример #2
0
        public async Task <ActionResult <CampModels> > Put(string moniker, CampModels models)
        {
            try
            {
                var oldCamp = await _campRepository.GetCampAsync(moniker);

                if (oldCamp == null)
                {
                    return(NotFound($"Moniker khong tim thay voi {moniker}"));
                }

                _mapper.Map(models, oldCamp);

                if (await _campRepository.SaveChangesAsync())
                {
                    return(_mapper.Map <CampModels>(oldCamp));
                }
            }
            catch (Exception)
            {
                return(this.StatusCode(500, "Database Failure"));
            }

            return(BadRequest());
        }
Пример #3
0
        public async Task <ActionResult <CampModels> > Get(string moniker)
        {
            try
            {
                var result = await _campRepository.GetCampAsync(moniker);

                CampModels campModels = _mapper.Map <CampModels>(result);
                return(campModels);
            }
            catch (Exception)
            {
                return(this.StatusCode(500, "Database Failure"));
            }
        }
Пример #4
0
        public async Task <ActionResult <CampModels> > GetById(int id, bool includeTalks = false)
        {
            try
            {
                var result = await campRepository.GetCampById(id, includeTalks);

                CampModels campModels = mapper.Map <CampModels>(result);
                return(campModels);
            }
            catch (Exception)
            {
                return(this.StatusCode(500, "Database Failure"));
            }
        }
Пример #5
0
        public async Task <ActionResult <CampModels> > SearchByDate(DateTime theDate)
        {
            try
            {
                var result = await campRepository.GetAllCampsByEventDate(theDate);

                if (!result.Any())
                {
                    return(NotFound());
                }
                CampModels campModels = mapper.Map <CampModels>(result);
                return(campModels);
            }
            catch (Exception)
            {
                return(this.StatusCode(500, "Database Failure"));
            }
        }