/// <summary> /// Luu thong tin mua quang cao /// JP - 05/07/2018 /// </summary> /// <returns></returns> //[Authorize] public JsonResult SaveBuyAdvertisement(AdvertisementCreateRequestModel model) { if (model != null) { model.UserId = UserId; model.ECurrencyId = _mySessionManager.WebInfoData.ECurrency; var res = _advertisementService.AddNewAdvertisement(model); return(Json(res)); } return(Json(1)); }
/// <summary> /// Thêm mới quảng cáo /// JP - 06/07/2018 /// </summary> /// <returns></returns> public ServiceResponse AddNewAdvertisement(AdvertisementCreateRequestModel model) { var response = new ServiceResponse(); try { var advUser = new Advertisement(); var newId = model.Id; if (newId > 0) { // update advUser = GetMulty(x => x.Id == model.Id && x.UserId == model.UserId).FirstOrDefault(); // Check exists if (advUser == null) { response.Message = "The advertisement is not exists"; return(response); } // Check status if (advUser.Status != AdvertisementStatusEnum.Available && advUser.Status != AdvertisementStatusEnum.Pending) { return(response); } // Check type if (advUser.AdvertisementType != model.AdvertisementType) { return(response); } } var userInfo = _appUserRepository.FindById(model.UserId); if (userInfo == null) { response.Message = "User is not exists"; return(response); } if (model.BitUSDPrice < 16000 || model.BitUSDPrice > 50000) { response.Message = "BitUSD not valid"; return(response); } // Check BitUSDRate if (model.BitUSDPrice < 20000) { response.Message = "Max coin price not valid"; return(response); } // Check CoinPriceLimit khong input if (model.CoinPriceLimit == -1) { model.CoinPriceLimit = model.BitcoinPriceMaker; } if (model.CoinPriceLimit == 0 || model.CoinPriceLimit < (model.BitcoinPriceMaker * (decimal)0.5)) { response.Message = "Max coin price not valid"; return(response); } var objAds = new Advertisement(); if (newId > 0) { advUser.BankId = model.BankId; advUser.BitcoinPriceMaker = model.BitcoinPriceMaker; advUser.BitcounPriceTaker = model.BitcounPriceTaker; advUser.BitUSDPrice = model.BitUSDPrice; advUser.BankAccountName = model.BankAccountName; advUser.BankAccountNumber = model.BankAccountNumber; advUser.CoinPriceLimit = model.CoinPriceLimit; advUser.CountryId = model.CountryId; advUser.CurrencyId = model.CurrencyId; advUser.ECurrencyId = model.ECurrencyId; advUser.MinAmount = model.MinAmount; advUser.MaxAmount = model.MaxAmount; advUser.PaymentMethod = model.PaymentMethod; advUser.PaymentTime = model.PaymentTime; advUser.ReferenceExchange = model.ReferenceExchange; advUser.RejectUserNotVeryfied = model.RejectUserNotVeryfied; //advUser.Status = AdvertisementStatusEnum.Available; //advUser.CreatedDate = DateTime.Now; advUser.UpdatedDate = DateTime.Now; _advertisementRepository.Update(advUser); } else { var objAdv = new Advertisement() { UserId = model.UserId, AdvertisementType = model.AdvertisementType, BankId = model.BankId, BitcoinPriceMaker = model.BitcoinPriceMaker, BitcounPriceTaker = model.BitcounPriceTaker, BitUSDPrice = model.BitUSDPrice, BankAccountName = model.BankAccountName, BankAccountNumber = model.BankAccountNumber, CoinPriceLimit = model.CoinPriceLimit, CountryId = model.CountryId, CurrencyId = model.CurrencyId, ECurrencyId = model.ECurrencyId, MinAmount = model.MinAmount, MaxAmount = model.MaxAmount, PaymentMethod = model.PaymentMethod, PaymentTime = model.PaymentTime, ReferenceExchange = model.ReferenceExchange, RejectUserNotVeryfied = model.RejectUserNotVeryfied, Status = AdvertisementStatusEnum.Available, CreatedDate = DateTime.Now }; _advertisementRepository.Add(objAdv); newId = objAdv.Id; } if (newId > 0) { response.Code = StatusCode.Success; response.Message = "Create advertisement successfully"; response.Data = new { Id = newId }; return(response); } } catch (Exception ex) { _log.LogError("AddNewAdvertisement:" + ex); } return(response); }