public BaseResponse <bool> Create(HotelInformationDetailCreateModel model)
        {
            try
            {
                if (model == null)
                {
                    return(BaseResponse <bool> .BadRequest());
                }

                var entity = _mapper.Map <HotelInformationDetailCreateModel, HotelInformationDetails>(model);
                var now    = DateTime.Now.Date;
                var userId = UserContextHelper.UserId;
                entity.UniqueId         = UniqueIDHelper.GenarateRandomString(12);
                entity.Deleted          = false;
                entity.IsActivated      = false;
                entity.LastModifiedBy   = userId;
                entity.LastModifiedDate = now;
                _db.HotelInformationDetails.Add(entity);
                _db.SaveChanges();

                return(BaseResponse <bool> .Success(true));
            }
            catch (Exception ex)
            {
                return(BaseResponse <bool> .InternalServerError(ex));
            }
        }
Пример #2
0
        private YachtTours GenerateYachtTourFromCreateModel(YachtTourCreateModel model)
        {
            var cityRespone     = _locationRequestService.GetCityNameById(model.CityFid);
            var countryRespone  = _locationRequestService.GetCountryNameById(model.CountryFid);
            var locationRespone = _locationRequestService.GetLocationNameById(model.CountryFid);

            var tour = new YachtTours();

            //tour.InjectFrom(model);
            //tour.TourDurationValue = model.TourDurationValue;
            tour = _mapper.Map <YachtTourCreateModel, YachtTours>(model, tour);
            //tour.TourDurationUnitResKey = (tour.TourDurationUnitTypeFid > 0) ? "TourDurationUnitResKey" : string.Empty;
            tour.City         = cityRespone.ResponseData ?? string.Empty;
            tour.Country      = countryRespone.ResponseData ?? string.Empty;
            tour.LocationName = locationRespone.ResponseData ?? string.Empty;

            var userId = UserContextHelper.UserId;
            var now    = DateTime.Now.Date;

            tour.UniqueId         = UniqueIDHelper.GenarateRandomString(12);
            tour.Deleted          = false;
            tour.IsActive         = false;
            tour.CreatedDate      = now;
            tour.LastModifiedDate = now;
            tour.CreatedBy        = userId;
            tour.LastModifiedBy   = userId;
            tour.UniqueId         = UniqueIDHelper.GenarateRandomString(12);
            return(tour);
        }
Пример #3
0
 public async Task<BasicResponse> CreateOrUpdateYachtAttribute(YachtAttributeCreateModel model)
 {
     try
     {
         var entity = _dbYachtContext.YachtAttributes.FirstOrDefault(x => x.Id == model.Id);
         if (entity != null)
         {
             entity = _mapper.Map<YachtAttributeCreateModel, YachtAttributes>(model, entity);
             entity.IsDefault = model.IsDefault;
             entity.LastModifiedBy = GetCurrentUserId();
             entity.LastModifiedDate = DateTime.Now;
             _dbYachtContext.YachtAttributes.Update(entity);
         }
         else
         {
             var newEntity = new YachtAttributes();
             newEntity = _mapper.Map<YachtAttributeCreateModel, YachtAttributes>(model, newEntity);
             newEntity.UniqueId = UniqueIDHelper.GenerateRandomString(12, false);
             newEntity.IsDefault = model.IsDefault;
             newEntity.CreatedBy = GetCurrentUserId();
             newEntity.CreatedDate = DateTime.Now;
             newEntity.LastModifiedBy = GetCurrentUserId();
             newEntity.LastModifiedDate = DateTime.Now;
             _dbYachtContext.YachtAttributes.Add(newEntity);
         }
         await _dbYachtContext.SaveChangesAsync();
         return BasicResponse.Succeed("Success");
     }
     catch
     {
         throw;
     }
 }
Пример #4
0
        //For AQ Account
        private AuthenticateViewModel GetAuthResponseModel(Users user)
        {
            try
            {
                if (user == null)
                {
                    return(null);
                }
                var authModel    = _mapper.Map <Users, AuthenticateViewModel>(user);
                var refreshToken = UniqueIDHelper.GenarateRandomString(12);
                user.RefreshToken = refreshToken;
                var saveSucceed = _accountService.UpdateUser(user).IsSuccessStatusCode;
                if (saveSucceed)
                {
                    authModel.RefreshToken            = refreshToken;
                    authModel.TokenEffectiveDate      = DateTime.Now.ToString();
                    authModel.TokenEffectiveTimeStick = DateTime.Now.Ticks.ToString();
                    authModel.AccountTypeFid          = ((int)AccountTypeEnum.Admin).ToString();
                    var result = JwtTokenHelper.GenerateJwtTokenModel(authModel, TOKEN_MINUTE_TIME_LIFE);
                    return(result);
                }

                return(null);
            }
            catch
            {
                return(null);
            }
        }
Пример #5
0
        public BaseResponse <string> Create(string token, string returnUrl)
        {
            try
            {
                if (string.IsNullOrEmpty(token) || JwtTokenHelper.DecodeJwtToken(token) == null)
                {
                    return(BaseResponse <string> .BadRequest());
                }

                var authModel = JwtTokenHelper.DecodeJwtToken(token);
                var userToken = new UserTokens()
                {
                    Id          = UniqueIDHelper.GenarateRandomString(12),
                    UserFid     = Guid.Parse(authModel.UserId),
                    AccessToken = token,
                    ReturnUrl   = returnUrl,
                };
                _db.UserTokens.Add(userToken);
                if (_db.SaveChanges() > 0)
                {
                    return(BaseResponse <string> .Success(userToken.Id));
                }
                return(BaseResponse <string> .BadRequest());
            }
            catch (Exception ex)
            {
                return(BaseResponse <string> .InternalServerError(message : ex.Message, fullMsg : ex.StackTrace));
            }
        }
Пример #6
0
        public virtual async Task <ApiActionResult> CreateAsync(TCreateModel model)
        {
            try
            {
                if (model == null)
                {
                    return(null);
                }
                var     userId   = GetUserGuidId();
                string  uniqueId = UniqueIDHelper.GenarateRandomString(12);
                TEntity entity   = new TEntity();
                entity.InjectFrom(model);
                entity.SetValueByNameIfExists("CreatedBy", userId);
                entity.SetValueByNameIfExists("CreatedDate", DateTime.UtcNow);
                entity.SetValueByNameIfExists("LastModifiedBy", userId);
                entity.SetValueByNameIfExists("LastModifiedDate", DateTime.UtcNow);
                entity.SetValueByNameIfExists("Deleted", false);
                entity.SetValueByNameIfExists("UniqueId", uniqueId);

                var result = await _repository.CreateEntityAsync(entity, userId);

                var viewModel = new TViewModel();
                viewModel.InjectFrom(result.ResponseData);
                return(await ApiActionResult.SuccessAsync(viewModel));
            }
            catch (Exception ex)
            {
                return(await ApiActionResult.FailedAsync(ex.Message));
            }
        }
Пример #7
0
        public async Task <BaseResponse <bool> > CreateAsync(HotelAttributeCreateModel model)
        {
            try
            {
                if (model == null)
                {
                    return(BaseResponse <bool> .BadRequest());
                }
                var createItem = new HotelAttributes();
                createItem.InjectFrom(model);
                createItem.UniqueId         = UniqueIDHelper.GenarateRandomString(12);
                createItem.Deleted          = false;
                createItem.UniqueId         = UniqueIDHelper.GenarateRandomString(12);
                createItem.CreatedBy        = GetUserGuidId();
                createItem.CreatedDate      = DateTime.UtcNow;
                createItem.LastModifiedBy   = GetUserGuidId();
                createItem.LastModifiedDate = DateTime.UtcNow;
                await _db.HotelAttributes.AddAsync(createItem);

                await _db.SaveChangesAsync();

                return(BaseResponse <bool> .Success(true));
            }
            catch (Exception ex)
            {
                return(BaseResponse <bool> .InternalServerError(message : ex.Message, fullMsg : ex.StackTrace));
            }
        }
        public async Task <BaseResponse <bool> > CreateYachtPricingPlans(YachtPricingPlanCreateModel model)
        {
            try
            {
                if (model == null)
                {
                    return(BaseResponse <bool> .BadRequest(false));
                }

                YachtPricingPlans yachtPricing = new YachtPricingPlans();
                yachtPricing                       = _mapper.Map <YachtPricingPlans>(model);
                yachtPricing.Deleted               = model.Deleted;
                yachtPricing.PricingCategoryFid    = model.PricingCategoryFid;
                yachtPricing.PricingCategoryResKey = model.PricingCategoryResKey;
                yachtPricing.UniqueId              = UniqueIDHelper.GenarateRandomString(12);
                yachtPricing.CreatedBy             = new Guid("B7A7A1E2-7F34-43E2-BE21-746F2271ECEC");
                yachtPricing.CreatedDate           = DateTime.Now;
                yachtPricing.LastModifiedBy        = new Guid("B7A7A1E2-7F34-43E2-BE21-746F2271ECEC");
                yachtPricing.LastModifiedDate      = DateTime.Now;
                yachtPricing.IsActivated           = model.IsActivated;
                await _context.YachtPricingPlans.AddAsync(yachtPricing);

                await _context.SaveChangesAsync();

                foreach (var item in model.lstPricingPlanDetail)
                {
                    YachtPricingPlanDetails yachtPricingDetail = new YachtPricingPlanDetails();
                    yachtPricingDetail = _mapper.Map <YachtPricingPlanDetails>(item);
                    yachtPricingDetail.PricingPlanFid = yachtPricing.Id;
                    yachtPricingDetail.Deleted        = false;
                    //yachtPricingDetail.CreatedBy = GetUserGuidId();
                    yachtPricingDetail.CreatedDate = DateTime.Now;
                    //yachtPricingDetail.LastModifiedBy = GetUserGuidId();
                    yachtPricingDetail.LastModifiedDate = DateTime.Now;
                    yachtPricingDetail.CultureCode      = model.CultureCode;
                    yachtPricingDetail.CurrencyCode     = model.CurrencyCode;
                    await _context.YachtPricingPlanDetails.AddAsync(yachtPricingDetail);

                    await _context.SaveChangesAsync();
                }
                YachtPricingPlanInformations yachtPricingInfo = new YachtPricingPlanInformations();
                yachtPricingInfo = _mapper.Map <YachtPricingPlanInformations>(model);
                yachtPricingInfo.PricingPlanFid   = yachtPricing.Id;
                yachtPricingInfo.Deleted          = false;
                yachtPricingInfo.LastModifiedBy   = new Guid("B7A7A1E2-7F34-43E2-BE21-746F2271ECEC");
                yachtPricingInfo.LastModifiedDate = DateTime.Now;
                await _context.YachtPricingPlanInformations.AddAsync(yachtPricingInfo);

                await _context.SaveChangesAsync();

                return(BaseResponse <bool> .Success());
            }
            catch (Exception ex)
            {
                return(BaseResponse <bool> .InternalServerError(message : ex.Message, fullMsg : ex.StackTrace));
            }
        }
Пример #9
0
 private YachtAdditionalServices DefaultYachtAdditionalServices() => new YachtAdditionalServices()
 {
     UniqueId         = UniqueIDHelper.GenarateRandomString(12),
     Deleted          = false,
     IsActive         = true,
     CreatedBy        = GetUserGuidId(),
     LastModifiedBy   = GetUserGuidId(),
     CreatedDate      = DateTime.Now.Date,
     LastModifiedDate = DateTime.Now.Date
 };
        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));
                }
            }
        }
Пример #11
0
        public long UpdatePostDetail(PostDetailCreateModel model)
        {
            try
            {
                var entity = _dbCMSContext.PostDetails.Find(model.Id);
                if (entity == null || entity.Deleted)
                {
                    throw new ArgumentNullException("Post detail");
                }
                int oldFileStreamId = entity.FileStreamFid;
                entity                  = _mapper.Map(model, entity);
                entity.UniqueId         = entity.UniqueId ?? UniqueIDHelper.GenerateRandomString(UNIQUE_ID_LENGTH);
                entity.LastModifiedDate = DateTime.Now;
                entity.LastModifiedBy   = _workContext.UserGuid;
                _dbCMSContext.SaveChanges();
                if (entity.Id > 0)
                {
                    if (model.FileStreamFid > 0 && oldFileStreamId != model.FileStreamFid)
                    {
                        #region Insert new post file stream
                        entity.FileTypeFid = (int)FileTypeEnum.Image;
                        var fileStreamModel = PreparingPostFileStreamCreateModel(entity, PostFileCategoryEnum.Thumbnail);
                        _postFileStreamService.CreatePostFileStream(fileStreamModel);
                        _postFileStreamService.DeletePostFileStream(oldFileStreamId);
                        #endregion
                    }
                    if (model.FileDescriptionIds.Count > 0)
                    {
                        foreach (var id in model.FileDescriptionIds)
                        {
                            var item = PreparingPostFileStreamCreateModel(entity, PostFileCategoryEnum.Detail);
                            item.FileStreamFid = id;
                            _postFileStreamService.CreatePostFileStream(item);
                        }
                    }

                    var havePostDetailActive = _dbCMSContext.PostDetails.Count(x => x.PostFid == entity.PostFid && x.IsActivated) > 0;

                    var post = _dbCMSContext.Posts.Find(entity.PostFid);
                    post.IsActivated      = havePostDetailActive;
                    post.LastModifiedBy   = _workContext.UserGuid;
                    post.LastModifiedDate = DateTime.Now;
                    _dbCMSContext.SaveChanges();
                }
                return(entity.Id);
            }
            catch (Exception ex)
            {
                AQException.ThrowException(ex);
                return(0);
            }
        }
Пример #12
0
        public BaseResponse <bool> Create(YachtOtherInformationAddOrUpdateModel model)
        {
            try
            {
                if (model == null)
                {
                    return(BaseResponse <bool> .BadRequest());
                }

                DateTime?activatedDate = null;
                if (!string.IsNullOrEmpty(model.ActivatedDate))
                {
                    activatedDate = model.ActivatedDate.ToNullDateTime();
                }

                var isExistedInfo = _context
                                    .YachtOtherInformations
                                    .Any(r => r.Deleted == false &&
                                         r.YachtFid == model.YachtFid &&
                                         r.ActivatedDate.GetValueOrDefault().Date == activatedDate.GetValueOrDefault().Date);
                if (isExistedInfo)
                {
                    return(BaseResponse <bool> .NotFound(false));
                }
                var userId = GetUserGuidId();
                var entity = new YachtOtherInformations();
                entity.UniqueId         = UniqueIDHelper.GenarateRandomString(12);
                entity.Title            = model.Title;
                entity.Descriptions     = model.Descriptions;
                entity.InfoTypeFid      = model.InfoTypeFid;
                entity.LanguageFid      = model.LanguageFid;
                entity.FileTypeFid      = model.FileTypeFid;
                entity.FileStreamFid    = model.FileStreamFid;
                entity.IsActivated      = true;
                entity.ActivatedBy      = userId;
                entity.ActivatedDate    = DateTime.Now;
                entity.LastModifiedBy   = userId;
                entity.LastModifiedDate = DateTime.Now;
                entity.CreatedBy        = userId;
                entity.CreatedDate      = DateTime.Now;
                _context.YachtOtherInformations.Add(entity);
                _context.SaveChanges();

                return(BaseResponse <bool> .Success(true));
            }
            catch (Exception ex)
            {
                return(BaseResponse <bool> .InternalServerError(message : ex.Message, fullMsg : ex.StackTrace));
            }
        }
Пример #13
0
        public bool CreateYachtMerchant(YachtMerchantCreateModel model)
        {
            using (var trans = _dbYachtContext.Database.BeginTransaction())
            {
                try
                {
                    var userGuid   = _workContext.UserGuid;
                    var userRoleId = _workContext.UserRoleId;
                    var entity     = _mapper.Map <YachtMerchants>(model);

                    entity.UniqueId         = UniqueIDHelper.GenerateRandomString(12, false);
                    entity.CreatedBy        = userGuid;
                    entity.CreatedDate      = DateTime.Now;
                    entity.LastModifiedBy   = userGuid;
                    entity.LastModifiedDate = DateTime.Now;
                    _dbYachtContext.YachtMerchants.Add(entity);
                    _dbYachtContext.SaveChanges();

                    if (userRoleId == (int)UserRoleEnum.YachtMerchantManager)
                    {
                        var merchantAccountMgt = new YachtMerchantAqmgts
                        {
                            AqadminUserFid     = userGuid,
                            MerchantFid        = entity.Id,
                            MerchantName       = entity.MerchantName,
                            CreatedBy          = userGuid,
                            CreatedDate        = DateTime.Now,
                            EffectiveStartDate = DateTime.Now,
                            EffectiveEndDate   = DateTime.Now.AddYears(1),
                            Deleted            = false,
                            LastModifiedBy     = userGuid,
                            LastModifiedDate   = DateTime.Now
                        };
                        _dbYachtContext.YachtMerchantAqmgts.AddAsync(merchantAccountMgt);
                        _dbYachtContext.SaveChanges();
                    }

                    trans.Commit();
                    trans.Dispose();
                    return(true);
                }
                catch (Exception ex)
                {
                    trans.Rollback();
                    trans.Dispose();
                    throw ex;
                }
            }
        }
Пример #14
0
 public BaseResponse <bool> Create(CommonValueCreateModel model)
 {
     try
     {
         var entity = _mapper.Map <CommonValueCreateModel, CommonValues>(model);
         entity.UniqueId = UniqueIDHelper.GenarateRandomString(12);
         _commonContext.CommonValues.Add(entity);
         _commonContext.SaveChanges();
         return(BaseResponse <bool> .Success(true));
     }
     catch (Exception ex)
     {
         return(BaseResponse <bool> .InternalServerError(ex));
     }
 }
Пример #15
0
        private YachtTourAttributes GenerateForCreate(YachtTourAttributeCreateModel model)
        {
            var entity = new YachtTourAttributes();

            entity.InjectFrom(model);
            entity.UniqueId = UniqueIDHelper.GenarateRandomString(12);
            var now    = DateTime.Now.Date;
            var userId = UserContextHelper.UserId;

            entity.LastModifiedBy   = userId;
            entity.CreatedBy        = userId;
            entity.LastModifiedDate = now;
            entity.CreatedDate      = now;
            return(entity);
        }
Пример #16
0
 public ApplicationUser() : base()
 {
     Id                   = Guid.NewGuid().ToString();
     EmailConfirmed       = false;
     PhoneNumberConfirmed = false;
     TwoFactorEnabled     = false;
     LockoutEnabled       = false;
     AccessFailedCount    = 5;
     ProviderName         = AuthProviderEnum.AqBooking.ToString();
     ProviderUserId       = Id;
     Deleted              = false;
     IsActivated          = true;
     RefreshToken         = UniqueIDHelper.GenarateRandomString(12);
     UniqueId             = UniqueIDHelper.GenarateRandomString(12);
 }
Пример #17
0
        public ApiActionResult CreateNewPost(PostCreateModel model)
        {
            try
            {
                model.UniqueId = UniqueIDHelper.GenerateRandomString(12);
                Posts obj = new Posts();
                obj = _mapper.Map <Posts>(model);
                obj.LastModifiedDate = model.LastModifiedDate;
                obj.Deleted          = false;
                var res = _dbCMSContext.Posts.Add(obj);
                _dbCMSContext.SaveChanges();
                if (res.Entity.Id > 0)
                {
                    model.postFileStream.ForEach(x => x.PostFid = res.Entity.Id);
                    var objFileStream = model.postFileStream.Select(k => new PostFileStreams
                    {
                        FileCategoryFid    = k.FileCategoryFid,
                        FileCategoryResKey = k.FileCategoryResKey,
                        PostFid            = res.Entity.Id,
                        FileStreamFid      = k.FileStreamFid,
                        FileTypeFid        = k.FileTypeFid,
                        FileTypeResKey     = k.FileTypeResKey,
                        ActivatedDate      = k.ActivatedDate,
                        LastModifiedDate   = model.LastModifiedDate.Value,
                        LastModifiedBy     = k.LastModifiedBy,
                        Deleted            = false
                    });
                    _dbCMSContext.PostFileStreams.AddRange(objFileStream);
                    _dbCMSContext.SaveChanges();
                    PostDetails objDetail = new PostDetails();
                    objDetail = _mapper.Map <PostDetails>(model.postDetail);
                    objDetail.LastModifiedDate = model.postDetail.LastModifiedDate;
                    objDetail.Deleted          = false;
                    objDetail.PostFid          = res.Entity.Id;
                    var resDetail = _dbCMSContext.PostDetails.Add(objDetail);
                    _dbCMSContext.SaveChanges();
                }
                return(ApiActionResult.Success());
            }
            catch (Exception ex)
            {
                return(ApiActionResult.Failed(ex.Message));

                throw ex;
            }
        }
Пример #18
0
        public ApiActionResult Create(CommonLanguaguesCreateModel model)
        {
            try
            {
                CommonLanguages obj = new CommonLanguages();
                obj          = _mapper.Map <CommonLanguages>(model);
                obj.UniqueId = UniqueIDHelper.GenerateRandomString(12);

                _dbConfigContext.CommonLanguages.Add(obj);
                _dbConfigContext.SaveChanges();
                return(ApiActionResult.Success());
            }
            catch (Exception ex)
            {
                return(ApiActionResult.Failed(ex.Message));
            }
        }
Пример #19
0
        public long CreatePostDetail(PostDetailCreateModel model)
        {
            try
            {
                var existsPost = GetPostDetailByPostIdAndLanguageId(model.PostFid, model.LanguageFid);
                if (existsPost != null)
                {
                    throw new ArgumentNullException($"Post is  existing with language={model.LanguageFid} and postId={model.PostFid}");
                }

                var entity = _mapper.Map <PostDetails>(model);
                entity.UniqueId         = UniqueIDHelper.GenerateRandomString(UNIQUE_ID_LENGTH);
                entity.LastModifiedDate = DateTime.Now;
                entity.LastModifiedBy   = _workContext.UserGuid;
                entity.Deleted          = false;

                _dbCMSContext.PostDetails.Add(entity);
                _dbCMSContext.SaveChanges();
                if (entity.Id > 0)
                {
                    if (model.FileStreamFid > 0)
                    {
                        entity.FileTypeFid = (int)FileTypeEnum.Image;
                        var fileStreamModel = PreparingPostFileStreamCreateModel(entity, PostFileCategoryEnum.Thumbnail);
                        _postFileStreamService.CreatePostFileStream(fileStreamModel);
                    }
                    if (model.FileDescriptionIds.Count > 0)
                    {
                        foreach (var id in model.FileDescriptionIds)
                        {
                            var item = PreparingPostFileStreamCreateModel(entity, PostFileCategoryEnum.Detail);
                            item.FileStreamFid = id;
                            _postFileStreamService.CreatePostFileStream(item);
                        }
                    }
                }

                return(entity.Id);
            }
            catch (Exception ex)
            {
                AQException.ThrowException(ex);
                return(0);
            }
        }
Пример #20
0
 public long CreateNewPost(PostCreateModel model)
 {
     try
     {
         var entity = _mapper.Map <Posts>(model);
         entity.Deleted     = false;
         entity.CreatedBy   = _workContext.UserGuid;
         entity.CreatedDate = DateTime.Now;
         entity.UniqueId    = UniqueIDHelper.GenerateRandomString(UNIQUE_ID_LENGTH);
         var res = _dbCMSContext.Posts.Add(entity);
         _dbCMSContext.SaveChanges();
         return(entity.Id);
     }
     catch (Exception ex)
     {
         AQException.ThrowException(ex);
         return(0);
     }
 }
Пример #21
0
        public ApiActionResult CreateNewCommonValues(CommonValueCreateModel model)
        {
            try
            {
                CommonValues obj = new CommonValues();
                obj          = _mapper.Map <CommonValueCreateModel, CommonValues>(model);
                obj.UniqueId = UniqueIDHelper.GenerateRandomString(12);
                _dbConfigContext.CommonValues.Add(obj);
                var flag = _dbConfigContext.SaveChanges();

                if (flag != 0)
                {
                    return(ApiActionResult.Success());
                }
                return(ApiActionResult.Failed("Created Failed"));
            }
            catch (Exception ex)
            {
                return(ApiActionResult.Failed(ex.Message));
            }
        }
Пример #22
0
        public bool CreateHotelMerchant(HotelMerchantCreateUpdateModel model)
        {
            var result = false;
            var entity = new HotelMerchants();

            entity                  = _mapper.Map <HotelMerchantCreateUpdateModel, HotelMerchants>(model, entity);
            entity.UniqueId         = UniqueIDHelper.GenerateRandomString(12);
            entity.CreatedBy        = _workContext.UserGuid;
            entity.CreatedDate      = DateTime.Now;
            entity.LastModifiedBy   = _workContext.UserGuid;
            entity.LastModifiedDate = DateTime.Now;
            var status = _dbHotelContext.HotelMerchants.Add(entity);

            _dbHotelContext.SaveChanges();

            if (status.State == EntityState.Unchanged)
            {
                result = true;
            }

            return(result);
        }
Пример #23
0
        public BaseResponse <int> Create(HotelCreateModel model)
        {
            try
            {
                //Return badRequest if model null
                if (model == null)
                {
                    return(BaseResponse <int> .BadRequest());
                }

                //Convert model to hotel
                var entity = _mapper.Map <HotelCreateModel, Hotels>(model);
                var now    = DateTime.Now.Date;
                var userId = UserContextHelper.UserId;

                //Generate private properties for hotel
                entity.UniqueId           = UniqueIDHelper.GenarateRandomString(12);
                entity.Deleted            = false;
                entity.ActiveForOperation = false;
                entity.CreatedDate        = now;
                entity.LastModifiedDate   = now;
                entity.CreatedBy          = userId;
                entity.LastModifiedBy     = userId;

                //Load Res Keys
                entity.StatusResKey        = _commonValueRequestService.Find(entity.StatusFid)?.ResponseData?.ResourceKey;
                entity.HotelTypeResKey     = _commonValueRequestService.Find(entity.HotelTypeFid)?.ResponseData?.ResourceKey;
                entity.HotelCategoryResKey = _commonValueRequestService.Find(entity.HotelCategoryFid)?.ResponseData?.ResourceKey;

                //Insert to database and return success
                _db.Hotels.Add(entity);
                _db.SaveChanges();
                return(BaseResponse <int> .Success(entity.Id));
            }
            catch (Exception ex)
            {
                return(BaseResponse <int> .InternalServerError(ex));
            }
        }
Пример #24
0
        public BaseResponse <bool> Create(HotelInformationCreateModel model)
        {
            using (var transaction = _db.Database.BeginTransaction())
            {
                try
                {
                    if (model != null)
                    {
                        //Create Info
                        var entity = _mapper.Map <HotelInformationCreateModel, HotelInformations>(model);
                        entity.DefaultTitle     = model.Title;
                        entity.UniqueId         = UniqueIDHelper.GenarateRandomString(12);
                        entity.Deleted          = false;
                        entity.IsActivated      = false;
                        entity.ActivatedBy      = UserContextHelper.UserId;
                        entity.LastModifiedDate = DateTime.Now.Date;
                        entity.LastModifiedBy   = UserContextHelper.UserId;
                        _db.HotelInformations.Add(entity);
                        _db.SaveChanges();

                        //Create Info Details
                        var detailsCreateModel = new HotelInformationDetailCreateModel();
                        detailsCreateModel.InjectFrom(model);
                        detailsCreateModel.ActivatedDate  = model.ActivatedDate.ToDateTime();
                        detailsCreateModel.InformationFid = entity.Id;
                        _hotelInformationDetailService.Create(detailsCreateModel);
                        transaction.Commit();
                        return(BaseResponse <bool> .Success(true));
                    }
                    return(BaseResponse <bool> .BadRequest());
                }
                catch (Exception ex)
                {
                    transaction.Rollback();
                    return(BaseResponse <bool> .InternalServerError(ex));
                }
            }
        }
Пример #25
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));
     }
 }
Пример #26
0
        public long UpdatePost(PostCreateModel model)
        {
            try
            {
                var entity = _dbCMSContext.Posts.Find(model.Id);
                if (entity == null || entity.Deleted)
                {
                    throw new ArgumentNullException("Post");
                }
                entity = _mapper.Map(model, entity);
                entity.LastModifiedBy   = _workContext.UserGuid;
                entity.LastModifiedDate = DateTime.Now;
                entity.UniqueId         = entity.UniqueId ?? UniqueIDHelper.GenerateRandomString(UNIQUE_ID_LENGTH);
                _dbCMSContext.SaveChanges();

                return(entity.Id);
            }
            catch (Exception ex)
            {
                AQException.ThrowException(ex);
                return(0);
            }
        }
Пример #27
0
        public virtual async Task <ApiActionResult> CreateRangeAsync(List <TCreateModel> models)
        {
            try
            {
                if (models == null)
                {
                    return(null);
                }
                var            userId   = GetUserGuidId();
                List <TEntity> entities = new List <TEntity>();
                foreach (var model in models)
                {
                    string  uniqueId = UniqueIDHelper.GenarateRandomString(12);
                    TEntity entity   = new TEntity();
                    entity.InjectFrom(model);
                    entity.SetValueByNameIfExists("CreatedBy", userId);
                    entity.SetValueByNameIfExists("CreatedDate", DateTime.UtcNow);
                    entity.SetValueByNameIfExists("LastModifiedBy", userId);
                    entity.SetValueByNameIfExists("LastModifiedDate", DateTime.UtcNow);
                    entity.SetValueByNameIfExists("Deleted", false);
                    entity.SetValueByNameIfExists("UniqueId", uniqueId);
                    entities.Add(entity);
                }

                var result = await _repository.CreateEntitiesAsync(entities, userId);

                if (result.Succeeded)
                {
                    return(await ApiActionResult.SuccessAsync());
                }
                return(await ApiActionResult.FailedAsync("Error"));
            }
            catch (Exception ex)
            {
                return(await ApiActionResult.FailedAsync(ex.Message));
            }
        }
Пример #28
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));
                }
            }
        }
        public BaseResponse <bool> CreateDetail(YachtTourInformationUpdateDetailModel model)
        {
            try
            {
                DateTime?activetdDate = null;
                if (model.ActivatedDate.HasValue)
                {
                    activetdDate = model.ActivatedDate.Value.Date;
                }

                if (model == null)
                {
                    return(BaseResponse <bool> .BadRequest(false));
                }

                var entity = new YachtTourInformationDetails();
                entity.InjectFrom(model);
                entity.InformationFid   = model.InformationFid;
                entity.UniqueId         = UniqueIDHelper.GenarateRandomString(12);
                entity.ActivatedBy      = _userId;
                entity.LastModifiedBy   = _userId;
                entity.LastModifiedDate = DateTime.Now;
                entity.ActivatedDate    = activetdDate;
                entity.IsActivated      = true;
                entity.Deleted          = false;

                _db.YachtTourInformationDetails.Add(entity);
                _db.SaveChangesAsync();

                return(BaseResponse <bool> .Success(true));
            }
            catch (Exception ex)
            {
                return(BaseResponse <bool> .InternalServerError(message : ex.Message, fullMsg : ex.StackTrace));
            }
        }
Пример #30
0
        public BaseResponse <bool> CreateDetail(YachtInformationCreateModel createModel)
        {
            try
            {
                DateTime?activetdDate = null;
                if (createModel.ActivatedDate.HasValue)
                {
                    activetdDate = createModel.ActivatedDate.Value.Date;
                }
                var userId = GetUserGuidId();
                var entity = new YachtInformationDetails();
                entity.InformationFid    = createModel.InformationFid;
                entity.FileStreamFid     = createModel.FileStreamFID;
                entity.FileTypeFid       = createModel.FileTypeFID;
                entity.LanguageFid       = createModel.LanguageFid;
                entity.Title             = createModel.Title;
                entity.ShortDescriptions = createModel.ShortDescriptions;
                entity.FullDescriptions  = createModel.FullDescriptions;
                entity.UniqueId          = UniqueIDHelper.GenarateRandomString(12);
                entity.ActivatedBy       = userId;;
                entity.LastModifiedBy    = userId;
                entity.LastModifiedDate  = DateTime.Now;
                entity.ActivatedDate     = activetdDate;
                entity.IsActivated       = true;
                entity.Deleted           = false;

                _context.YachtInformationDetails.Add(entity);
                _context.SaveChangesAsync();

                return(BaseResponse <bool> .Success(true));
            }
            catch (Exception ex)
            {
                return(BaseResponse <bool> .InternalServerError(message : ex.Message, fullMsg : ex.StackTrace));
            }
        }