コード例 #1
0
        public BaseResponse <bool> Create(YachtTourInformationCreateModel model)
        {
            using (var transaction = _db.Database.BeginTransaction())
            {
                try
                {
                    if (model == null)
                    {
                        return(BaseResponse <bool> .BadRequest(false));
                    }
                    var rs = _commonValueService.GetListCommonValueByGroup(CommonValueGroupConstant.TourInfoType);

                    DateTime?activetdDate = null;
                    if (model.ActivatedDate.HasValue)
                    {
                        activetdDate = model.ActivatedDate.Value.Date;
                    }
                    var date = DateTime.Now.Date;

                    var info = new YachtTourInformations();
                    info.InjectFrom(model);
                    info.TourInformationTypeResKey = rs.IsSuccessStatusCode ?
                                                     rs.ResponseData.FirstOrDefault(x => x.ValueInt == model.TourInformationTypeFid).ResourceKey : null;
                    info.DefaultTitle     = model.Title;
                    info.UniqueId         = UniqueIDHelper.GenarateRandomString(12);
                    info.LastModifiedBy   = _userId;
                    info.LastModifiedDate = date;
                    info.IsActivated      = true;
                    info.ActivatedBy      = _userId;
                    info.Deleted          = false;
                    _db.YachtTourInformations.Add(info);
                    _db.SaveChanges();

                    var detail = new YachtTourInformationDetails();
                    detail.InjectFrom(model);
                    detail.InformationFid   = info.Id;
                    detail.UniqueId         = UniqueIDHelper.GenarateRandomString(12);
                    detail.ActivatedBy      = _userId;
                    detail.LastModifiedBy   = _userId;
                    detail.LastModifiedDate = date;
                    detail.IsActivated      = true;
                    detail.Deleted          = false;
                    _db.YachtTourInformationDetails.Add(detail);
                    _db.SaveChanges();

                    transaction.Commit();
                    return(BaseResponse <bool> .Success(true));
                }
                catch (Exception ex)
                {
                    transaction.Rollback();
                    return(BaseResponse <bool> .InternalServerError(message : ex.Message, fullMsg : ex.StackTrace));
                }
            }
        }
コード例 #2
0
 public BaseResponse <bool> Create(YachtTourAttributeValueCreateModel model)
 {
     try
     {
         var entity = GenerateForCreate(model);
         _db.YachtTourAttributeValues.Add(entity);
         var resul = _db.SaveChanges();
         return(resul > 0
                 ? BaseResponse <bool> .Success(true)
                 : BaseResponse <bool> .BadRequest());
     }
     catch (Exception ex)
     {
         return(BaseResponse <bool> .InternalServerError(message : ex.Message, fullMsg : ex.StackTrace));
     }
 }
コード例 #3
0
        public BaseResponse <bool> Create(int tourId, int yachtId, YachtTourPricingCreateModel model)
        {
            try
            {
                if (tourId < 1 || yachtId < 1 || model == null)
                {
                    return(BaseResponse <bool> .BadRequest());
                }

                var entity = GenerateForCreate(tourId, yachtId, model);
                _db.YachtTourPricings.Add(entity);
                var save = _db.SaveChanges();
                return(save > 0 ? BaseResponse <bool> .Success(true) : BaseResponse <bool> .BadRequest());
            }
            catch (Exception ex)
            {
                return(BaseResponse <bool> .InternalServerError(message : ex.Message, fullMsg : ex.StackTrace));
            }
        }
コード例 #4
0
        public BaseResponse <bool> Create(List <YachtTourNonOperationDayCreateModel> models)
        {
            try
            {
                var entities = new List <YachtTourNonOperationDays>();
                foreach (var m in models)
                {
                    entities.Add(GenerateCreateModel(m));
                }
                _db.YachtTourNonOperationDays.AddRange(entities);
                var result = _db.SaveChanges();
                if (result > 0)
                {
                    return(BaseResponse <bool> .Success(true));
                }

                return(BaseResponse <bool> .BadRequest());
            }
            catch (Exception ex)
            {
                return(BaseResponse <bool> .InternalServerError(message : ex.Message, fullMsg : ex.StackTrace));
            }
        }
コード例 #5
0
        public BaseResponse <bool> Update(YachtTourFileStreamUpdateModel model, long fileID)
        {
            try
            {
                var commonValue = _commonValueService.GetListCommonValueByGroup(CommonValueGroupConstant.YachtTourImageCategory);

                var entity = _db.YachtTourFileStreams
                             .FirstOrDefault(k => !k.Deleted && k.Id == fileID);
                entity = GenerateForUpdate(entity);
                if (entity == null)
                {
                    return(BaseResponse <bool> .BadRequest());
                }
                entity.InjectFrom(model);

                if (commonValue.IsSuccessStatusCode)
                {
                    entity.FileCategoryResKey = commonValue.IsSuccessStatusCode ?
                                                commonValue.ResponseData.FirstOrDefault(x => x.ValueInt == model.FileCategoryFid).ResourceKey : null;
                }
                else
                {
                    entity.FileCategoryResKey = null;
                }

                var result = _db.SaveChanges();
                if (result > 0)
                {
                    return(BaseResponse <bool> .Success(true));
                }
                return(BaseResponse <bool> .BadRequest(message : "Save Changes fail"));
            }
            catch (Exception ex)
            {
                return(BaseResponse <bool> .InternalServerError(message : ex.Message, fullMsg : ex.StackTrace));
            }
        }
コード例 #6
0
        public BaseResponse <bool> Delete(long id)
        {
            var entity = _db.YachtTourExternalRefLinks.Find(id);

            if (entity != null && !entity.Deleted)
            {
                entity.Deleted          = true;
                entity.LastModifiedBy   = UserContextHelper.UserId;
                entity.LastModifiedDate = DateTime.Now;
                _db.YachtTourExternalRefLinks.Update(entity);
                _db.SaveChanges();
                return(BaseResponse <bool> .Success(true));
            }
            return(BaseResponse <bool> .InternalServerError());
        }
コード例 #7
0
 public BaseResponse <bool> Create(YachtTourCounterCreateModel createModel)
 {
     try
     {
         if (createModel == null)
         {
             return(BaseResponse <bool> .BadRequest());
         }
         var entity = _mapper.Map <YachtTourCounterCreateModel, YachtTourCounters>(createModel);
         entity.YachtTourUniqueId = UniqueIDHelper.GenarateRandomString(12);
         _db.YachtTourCounters.Add(entity);
         var result = _db.SaveChanges();
         if (result > 0)
         {
             return(BaseResponse <bool> .Success(true));
         }
         return(BaseResponse <bool> .BadRequest());
     }
     catch (Exception ex)
     {
         return(BaseResponse <bool> .InternalServerError(message : ex.Message, fullMsg : ex.StackTrace));
     }
 }
コード例 #8
0
        public BaseResponse <string> Create(YachtTourCreateModel model)
        {
            using (var transaction = _db.Database.BeginTransaction())
            {
                try
                {
                    var tour = GenerateYachtTourFromCreateModel(model);
                    if (tour == null)
                    {
                        return(BaseResponse <string> .BadRequest());
                    }
                    _db.YachtTours.Add(tour);
                    _db.SaveChanges();

                    var counter = new YachtTourCounters();
                    counter.YachtTourId          = tour.Id;
                    counter.YachtTourUniqueId    = UniqueIDHelper.GenarateRandomString(12);
                    counter.TotalViews           = 1000;
                    counter.TotalBookings        = 100;
                    counter.TotalSuccessBookings = 1000;
                    counter.TotalReviews         = 10000;
                    counter.TotalRecommendeds    = 100;
                    counter.TotalNotRecommendeds = 1;
                    _db.YachtTourCounters.Add(counter);
                    _db.SaveChanges();

                    transaction.Commit();
                    return(BaseResponse <string> .Success(Terminator.Encrypt(tour.Id.ToString())));
                }
                catch (Exception ex)
                {
                    transaction.Rollback();
                    return(BaseResponse <string> .InternalServerError(message : ex.Message, fullMsg : ex.StackTrace));
                }
            }
        }