public async Task <IActionResult> Add([FromBody] TourDTO tour)
        {
            if (ModelState.IsValid)
            {
                tour = await _tourService.Add(tour);

                return(Ok(tour));
            }
            return(BadRequest(ModelState));
        }
Exemple #2
0
        //[Authorize(Roles = nameof(PermissionProvider.AddArea))]
        public HttpResponseMessage Create(HttpRequestMessage request, TourDto tourDto)
        {
            return(CreateHttpResponse(request, () =>
            {
                HttpResponseMessage reponse = null;
                if (!ModelState.IsValid)
                {
                    reponse = request.CreateResponse(HttpStatusCode.BadRequest, ModelState);
                }
                else
                {
                    this.msg = "Trùng code";
                    if (_tourService.CheckCode(tourDto.Code))
                    {
                        reponse = request.CreateResponse(HttpStatusCode.BadRequest, msg);
                    }
                    var modelTour = Mapper.Map <Tour>(tourDto);
                    modelTour.Code = modelTour.Code.Trim().ToUpper();
                    modelTour.FromDate = modelTour.FromDate.UtcDateTime;
                    modelTour.ToDate = modelTour.ToDate.UtcDateTime;
                    modelTour.CreatedDate = GetDateTimeNowUTC();
                    modelTour.CreatedBy = User.Identity.GetUserId();
                    modelTour.Alias = StringHelper.ToUrlFriendlyWithDateTime(modelTour.Name, modelTour.CreatedDate.Value.DateTime);
                    _uow.BeginTran();
                    _tourService.Add(modelTour);

                    if (tourDto.TourAttr.Count > 0)
                    {
                        foreach (var item in tourDto.TourAttr)
                        {
                            item.TourId = modelTour.Id;
                        }
                    }
                    var modelAttrs = Mapper.Map <List <TourAttributeValue> >(tourDto.TourAttr);
                    _tourAttributeValueService.Add(modelAttrs);

                    _uow.CommitTran();

                    reponse = request.CreateResponse(HttpStatusCode.Created, modelTour);
                }
                return reponse;
            }));
        }