} //Asynchronous callback address protected override void dataValidate() { //AutoDebitNo validation if (string.IsNullOrEmpty(autoDebitNo)) { throw new YuanpayException("autoDebitNo is missing"); } //Amount validation ParamValidator.amountValidate("amount", amount); //Currency validation if (string.IsNullOrEmpty(currency)) { throw new YuanpayException("currency is missing"); } //Settlement Currency validation if (string.IsNullOrEmpty(settleCurrency)) { throw new YuanpayException("settleCurrency is missing"); } //Reference validation if (string.IsNullOrEmpty(reference)) { throw new YuanpayException("reference is missing"); } //IpnUrl validation if (string.IsNullOrEmpty(ipnUrl)) { throw new YuanpayException("ipnUrl is missing"); } }
} //Refund transaction reference protected override void dataValidate() { //Amount validation ParamValidator.amountValidate("refundAmount", refundAmount); //Currency validation if (string.IsNullOrEmpty(currency)) { throw new YuanpayException("currency is missing"); } //Settlement Currency validation if (string.IsNullOrEmpty(settleCurrency)) { throw new YuanpayException("settleCurrency is missing"); } //TransactionNo and Reference validation if (string.IsNullOrEmpty(transactionNo) && string.IsNullOrEmpty(reference)) { throw new YuanpayException("transaction number and reference cannot be null at the same time"); } if (!string.IsNullOrEmpty(transactionNo) && !string.IsNullOrEmpty(reference)) { throw new YuanpayException("transaction number and reference cannot exist at the same time"); } }
public void Log(LogLevel logLevel, Exception exception, Type loggingType, bool notifyAdministrator, string stringFormat, params object[] args) { ParamValidator.AssertIsNotEmpty(stringFormat, "stringFormat"); try { LoggingEventData logData = new LoggingEventData() { Level = TransformToLevel(logLevel), ExceptionString = exception != null ? string.Format("{0}|StackTrace: {1}", exception.Message, exception.StackTrace) : null, ThreadName = loggingType != null ? loggingType.ToString() : null, TimeStamp = _clock.Now, Message = string.Format(stringFormat, args), LoggerName = LoggerName, }; LoggingEvent logEvent = new LoggingEvent(logData); _logger.Logger.Log(logEvent); } catch { //// Don't do nothing, logger classes don't have to throw any exceptions. } }
protected override void dataValidate() { //Validate if infos are missing if (string.IsNullOrEmpty(outAuthInfoNo)) { throw new YuanpayException("outAuthInfoNo missing"); } if (string.IsNullOrEmpty(outAuthDetailNo)) { throw new YuanpayException("outAuthDetailNo missing"); } if (string.IsNullOrEmpty(vendor)) { throw new YuanpayException("vendor missing"); } //币种校验 if (string.IsNullOrEmpty(currency)) { throw new YuanpayException("currency missing."); } if (string.IsNullOrEmpty(settleCurrency)) { throw new YuanpayException("settleCurrency missing"); } ParamValidator.amountValidate("amount", amount); }
} //Transaction reference number protected override void dataValidate() { //Amount validation ParamValidator.amountValidate("amount", amount); //Currency validation if (string.IsNullOrEmpty(currency)) { throw new YuanpayException("currency is missing"); } bool currencyFlag = CurrencyEnums.containValidate(currency); if (!currencyFlag) { throw new YuanpayException("data error: currency"); } //Settlement Currency validation if (string.IsNullOrEmpty(settleCurrency)) { throw new YuanpayException("settleCurrency is missing"); } bool settleCurrencyFlag = SettleCurrencyEnums.containValidate(settleCurrency); if (!settleCurrencyFlag) { throw new YuanpayException("data error: settleCurrency"); } //Reference validation if (string.IsNullOrEmpty(reference)) { throw new YuanpayException("reference is missing"); } }
public IActionResult InsertRole(InsertRoleDto input) { try { #region Validation var validator = new ParamValidator(); validator.ValidateNull(input.Name, General.Messages_.NullInputMessages_.GeneralNullMessage("عنوان")) .Throw(General.Results_.FieldNullErrorCode()); #endregion var role = new Role { Cdate = DateTime.Now.Ticks, CuserId = ClaimPrincipalFactory.GetUserId(User), Name = input.Name, Rkey = input.Rkey }; _repository.Role.Create(role); _repository.Save(); _logger.LogData(MethodBase.GetCurrentMethod(), role.Id, null, input); return(Ok(role.Id)); } catch (Exception e) { _logger.LogError(e, MethodBase.GetCurrentMethod(), input); return(BadRequest(e.Message)); } }
public IActionResult UpdatetRole([FromBody] InsertRoleDto input, [FromQuery] long roleId) { try { var role = _repository.Role.FindByCondition(c => c.Id == roleId).FirstOrDefault(); #region Validation var validator = new ParamValidator(); validator.ValidateNull(input.Name, General.Messages_.NullInputMessages_.GeneralNullMessage("عنوان")) .Throw(General.Results_.FieldNullErrorCode()); if (role == null) { throw new BusinessException(XError.GetDataErrors.NotFound()); } #endregion role.Mdate = DateTime.Now.Ticks; role.MuserId = ClaimPrincipalFactory.GetUserId(User); role.Name = input.Name; role.Rkey = input.Rkey; _repository.Role.Update(role); _repository.Save(); _logger.LogData(MethodBase.GetCurrentMethod(), General.Results_.SuccessMessage(), null, input, roleId); return(Ok(General.Results_.SuccessMessage())); } catch (Exception e) { _logger.LogError(e, MethodBase.GetCurrentMethod(), input, roleId); return(BadRequest(e.Message)); } }
protected override void dataValidate() { if (string.IsNullOrEmpty(outAuthInfoNo) && string.IsNullOrEmpty(authInfoNo)) { throw new YuanpayException("outAuthInfoNo and authInfoNo missing"); } if (!string.IsNullOrEmpty(outAuthDetailNo) && !string.IsNullOrEmpty(authInfoNo)) { throw new YuanpayException("outAuthInfoNo and authInfoNo cannot exist at the same time"); } if (string.IsNullOrEmpty(outAuthDetailNo)) { throw new YuanpayException("outAuthDetailNo missing"); } if (string.IsNullOrEmpty(currency)) { throw new YuanpayException("currency missing"); } if (string.IsNullOrEmpty(settleCurrency)) { throw new YuanpayException("settleCurrency missing"); } ParamValidator.amountValidate("unfreezeAmount", unfreezeAmount); }
public IActionResult InsertEmployee(EmployeeInsertDto input) { try { #region Validation var validator = new ParamValidator(); validator.ValidateNull(input.FirstName, General.Messages_.NullInputMessages_.GeneralNullMessage("نام")) .ValidateNull(input.LastName, General.Messages_.NullInputMessages_.GeneralNullMessage("نام خانوادگی")) .ValidateNull(input.UserName, General.Messages_.NullInputMessages_.GeneralNullMessage("نام کاربری")) .ValidateNull(input.Password, General.Messages_.NullInputMessages_.GeneralNullMessage("رمز عبور")) .Throw(General.Results_.FieldNullErrorCode()); if (input.RoleList.Count == 0) { throw new BusinessException(XError.BusinessErrors.RoleNotSelected()); } if (_repository.Users.FindByCondition(c => c.Username == input.UserName).Any()) { throw new BusinessException(XError.BusinessErrors.UserAlreadyExists()); } #endregion var employee = new Employee(); var user = new Users { Cdate = DateTime.Now.Ticks, CuserId = ClaimPrincipalFactory.GetUserId(User), FullName = input.FirstName + " " + input.LastName, Hpassword = input.Password, Username = input.UserName }; input.RoleList.ForEach(c => { var userRole = new UserRole { Cdate = DateTime.Now.Ticks, CuserId = ClaimPrincipalFactory.GetUserId(User), Role = c }; user.UserRole.Add(userRole); }); employee.User = user; _repository.Employee.Create(employee); _repository.Save(); _logger.LogData(MethodBase.GetCurrentMethod(), employee.Id, null, input); return(Ok(employee.Id)); } catch (Exception e) { _logger.LogError(e, MethodBase.GetCurrentMethod(), input); return(BadRequest(e.Message)); } }
public IActionResult InsertOffer(OfferInsertDto offerInsert) { try { ParamValidator validator = new ParamValidator(); validator.ValidateNull(offerInsert.FromDate, General.Messages_.NullInputMessages_.GeneralNullMessage("از تاریخ")) .ValidateNull(offerInsert.ToDate, General.Messages_.NullInputMessages_.GeneralNullMessage("تا تاریخ")) .ValidateNull(offerInsert.Name, General.Messages_.NullInputMessages_.GeneralNullMessage("عنوان")) .ValidateNull(offerInsert.Value, General.Messages_.NullInputMessages_.GeneralNullMessage("مقدار تخفیف")) .ValidateNull(offerInsert.MaximumPrice, General.Messages_.NullInputMessages_.GeneralNullMessage("حداکثر قیمت")) .ValidateNull(offerInsert.OfferTypeId, General.Messages_.NullInputMessages_.GeneralNullMessage("نوع تخفیف")) .ValidateNull(offerInsert.OfferCode, General.Messages_.NullInputMessages_.GeneralNullMessage("کد تخفیف")) .Throw(General.Results_.FieldNullErrorCode()); var offer = new Offer { Cdate = DateTime.Now.Ticks, CuserId = ClaimPrincipalFactory.GetUserId(User), Description = offerInsert.Description, FromDate = offerInsert.FromDate?.Ticks ?? 0, HaveTimer = offerInsert.HaveTimer, MaximumPrice = offerInsert.MaximumPrice, Name = offerInsert.Name, OfferCode = offerInsert.OfferCode, OfferTypeId = offerInsert.OfferTypeId, ToDate = offerInsert.ToDate?.Ticks ?? 0, Value = offerInsert.Value }; offerInsert.ProductIdList.ForEach(c => { var productOffer = new ProductOffer { Cdate = DateTime.Now.Ticks, CuserId = ClaimPrincipalFactory.GetUserId(User), ProductId = c, Value = offerInsert.Value, FromDate = offerInsert.FromDate?.Ticks ?? 0, ToDate = offerInsert.ToDate?.Ticks ?? 0, LanguageId = offerInsert.LanguageId }; offer.ProductOffer.Add(productOffer); }); _repository.Offer.Create(offer); _repository.Save(); _logger.LogData(MethodBase.GetCurrentMethod(), offer.Id, null, offerInsert); return(Ok(offer.Id)); } catch (Exception e) { _logger.LogError(e, MethodBase.GetCurrentMethod(), offerInsert); return(BadRequest(e.Message)); } }
public IActionResult InsertProductPackingList(ProductPackingListInsertDto input) { try { var validator = new ParamValidator(); validator.ValidateNull(input.Title, General.Messages_.NullInputMessages_.GeneralNullMessage("نام")) .ValidateNull(input.PackingTypeId, General.Messages_.NullInputMessages_.GeneralNullMessage("کد بسته بندی")) .Throw(General.Results_.FieldNullErrorCode()); var packingType = _repository.PackingType.FindByCondition(c => c.Id == input.PackingTypeId && c.DaDate == null && c.Ddate == null).FirstOrDefault(); if (packingType == null || packingType.Count < 1) { throw new BusinessException(XError.BusinessErrors.InvalidPackingType()); } var packingList = new ProductPackingTypeList { Cdate = DateTime.Now.Ticks, CuserId = ClaimPrincipalFactory.GetUserId(User), Title = input.Title, }; input.ProductIdList.ForEach(c => { var pp = new ProductPackingType { Cdate = DateTime.Now.Ticks, CuserId = ClaimPrincipalFactory.GetUserId(User), PackinggTypeId = input.PackingTypeId, ProductId = c, Price = packingType.Price }; packingList.ProductPackingType.Add(pp); }); packingType.Count -= 1; _repository.ProductPackingTypeList.Create(packingList); _repository.PackingType.Update(packingType); _repository.Save(); _logger.LogData(MethodBase.GetCurrentMethod(), packingList.Id, null, input); return(Ok(packingType.Id)); } catch (Exception e) { _logger.LogError(e, MethodBase.GetCurrentMethod(), input); return(BadRequest(e.Message)); } }
public VarianceScaling(float scale = 1f, string mode = "fan_in", string distribution = "normal") { if (scale < 1f) { throw new ArgumentException("Scale must be positive value"); } ParamValidator.Validate("mode", mode, "fan_in", "fan_out", "fan_avg"); ParamValidator.Validate("distribution", distribution, "normal", "uniform"); Scale = scale; Mode = mode; Distribution = distribution; }
public string note { get; set; } //Transaction note protected override void dataValidate() { //Amount validation ParamValidator.amountValidate("amount", amount); //Reference number validation if (string.IsNullOrEmpty(reference)) { throw new YuanpayException("reference is missing"); } //Currency validation if (string.IsNullOrEmpty(currency)) { throw new YuanpayException("currency is missing"); } if (string.IsNullOrEmpty(settleCurrency)) { throw new YuanpayException("settleCurrency is missing"); } //Vendor validation if (string.IsNullOrEmpty(vendor)) { throw new YuanpayException("vendor is missing"); } //Terminal validation if (string.IsNullOrEmpty(terminal)) { throw new YuanpayException("terminal is missing"); } if(VendorEnums.ALIPAY.Value.Equals(vendor) && !TerminalEnums.APP.Value.Equals(terminal)) { throw new YuanpayException("data error: terminal"); } //Openid validation if (VendorEnums.WECHATPAY.Value.Equals(vendor)) { if (TerminalEnums.MINIPROGRAM.Value.Equals(terminal) && string.IsNullOrEmpty(openid)) { throw new YuanpayException("openid is missing"); } } }
protected override void dataValidate() { //Validation if (string.IsNullOrEmpty(cardNumber)) { throw new YuanpayException("cardNumber missing"); } if (string.IsNullOrEmpty(cardExpYear)) { throw new YuanpayException("cardExpYear missing"); } if (string.IsNullOrEmpty(cardExpMonth)) { throw new YuanpayException("cardExpMonth missing"); } if (string.IsNullOrEmpty(cardCvv)) { throw new YuanpayException("cardCvv missing"); } ParamValidator.numberValidate("cardNumber", cardNumber); ParamValidator.numberValidate("cardExpYear", cardExpYear); ParamValidator.numberValidate("cardExpMonth", cardExpMonth); ParamValidator.numberValidate("cardCvv", cardCvv); ParamValidator.amountValidate("amount", amount); if (string.IsNullOrEmpty(currency)) { throw new YuanpayException("currency missing."); } if (string.IsNullOrEmpty(settleCurrency)) { throw new YuanpayException("settleCurrency missing"); } if (string.IsNullOrEmpty(reference)) { throw new YuanpayException("reference missing"); } if (string.IsNullOrEmpty(clientIp)) { throw new YuanpayException("clientIp missing"); } }
} //The subject line for the email the gets sent out when a payment is completed. //Data validation protected override void dataValidate() { //Amount validation ParamValidator.amountValidate("amount", amount); //Reference validation if (string.IsNullOrEmpty(customerNo)) { throw new YuanpayException("customerNo is missing"); } if (string.IsNullOrEmpty(accountToken)) { throw new YuanpayException("accountToken is missing"); } //Currency validation if (string.IsNullOrEmpty(currency)) { throw new YuanpayException("currency is missing"); } if (!string.IsNullOrEmpty(invoiceId)) { throw new YuanpayException("invoiceId is missing"); } if (!string.IsNullOrEmpty(description)) { if (description.Length > 100) { throw new YuanpayException("description is too long"); } } if (!string.IsNullOrEmpty(note)) { if (note.Length > 100) { throw new YuanpayException("note is too long"); } } }
public IActionResult InsertComission(InsertComissionDto input) { try { var userId = ClaimPrincipalFactory.GetUserId(User); #region Validation var validator = new ParamValidator(); validator.ValidateNull(input.Title, General.Messages_.NullInputMessages_.GeneralNullMessage("عنوان")) .ValidateNull(input.Value, General.Messages_.NullInputMessages_.GeneralNullMessage("مقدار کمیسیون")) .Throw(General.Results_.FieldNullErrorCode()); if (input.Value > 70) { throw new BusinessException("مقدار کمیسیون نباید بیشتر از 70 باشد.", 1001); } if (input.ProductIdList.Count == 0) { throw new BusinessException("محصولی انتخاب نشده است.", 1001); } #endregion var productIdList = new List <Product>(); var comission = new Comission { Cdate = DateTime.Now.Ticks, CuserId = userId, SendEmail = input.SendEmail, SendSms = input.SendSms, Title = input.Title, Value = input.Value, ProductComission = new List <ProductComission>() }; input.ProductIdList.ForEach(c => { #region Change Product Status var product = _repository.Product.FindByCondition(x => x.Id == c).Include(c => c.Seller).FirstOrDefault(); if (product == null) { throw new BusinessException("کد محصولات صحیح نیست", 1001); } productIdList.Add(product); product.FinalStatusId = 7; _repository.Product.Update(product); #endregion #region Deactive Previous Comission var _productComission = _repository.ProductComission .FindByCondition(x => x.ProductId == c && x.DaDate == null).FirstOrDefault(); if (_productComission != null) { _productComission.DaDate = DateTime.Now.Ticks; _productComission.DaUserId = userId; _repository.ProductComission.Update(_productComission); } #endregion var productComission = new ProductComission { CuserId = userId, Cdate = DateTime.Now.Ticks, ProductId = c, }; comission.ProductComission.Add(productComission); }); #region SendSms if (input.SendSms) { productIdList.ForEach(c => { var sms = new SendSMS(); sms.SendChangeComissionSms(c.Seller.Mobile.Value, c.Seller.Name + " " + c.Seller.Fname, c.Name, comission.Value.Value); }); } #endregion #region SendEmail if (input.SendEmail) { productIdList.ForEach(c => { var email = new SendEmail(); email.SendChangeComissionEmail(c.Seller.Email, c.Seller.Name + " " + c.Seller.Fname, c.Name, comission.Value.Value); }); } #endregion _repository.Comission.Create(comission); _repository.Save(); _logger.LogData(MethodBase.GetCurrentMethod(), comission.Id, null, input); return(Ok(comission.Id)); } catch (Exception e) { _logger.LogError(e, MethodBase.GetCurrentMethod(), input); return(BadRequest(e.Message)); } }
//Data validation protected override void dataValidate() { //Amount validation ParamValidator.amountValidate("amount", amount); //Reference validation if (string.IsNullOrEmpty(reference)) { throw new YuanpayException("reference is missing"); } //Currency validation if (string.IsNullOrEmpty(currency)) { throw new YuanpayException("currency is missing"); } //Settlement Currency validation if (string.IsNullOrEmpty(settleCurrency)) { throw new YuanpayException("currency is missing"); } //Vendor validation if (string.IsNullOrEmpty(vendor)) { throw new YuanpayException("vendor is missing"); } //Terminal validation if (string.IsNullOrEmpty(terminal)) { throw new YuanpayException("terminal is missing"); } //Description and note validation if (!string.IsNullOrEmpty(description)) { if (description.Length > 100) { throw new YuanpayException("description is too long"); } } if (!string.IsNullOrEmpty(note)) { if (note.Length > 100) { throw new YuanpayException("note is too long"); } } //Goods Info validation if (!string.IsNullOrEmpty(goodsInfo)) { var token = JToken.Parse(goodsInfo); bool jsonFlag = token is JArray; if (!jsonFlag) { throw new YuanpayException("goodsInfo should be json array format"); } } }
public IActionResult UpdatePackage([FromForm] InsertPackageDto input, [FromForm] FormFileCollection fileList) { try { var validator = new ParamValidator(); validator.ValidateNull(input.Name, General.Messages_.NullInputMessages_.GeneralNullMessage("عنوان")) .ValidateNull(input.Price, General.Messages_.NullInputMessages_.GeneralNullMessage("قیمت")) .ValidateNull(input.PackageId, General.Messages_.NullInputMessages_.GeneralNullMessage("آیدی پکیج")) .Throw(General.Results_.FieldNullErrorCode()); if (input.ProductWithPriceList.Count == 0) { throw new BusinessException("محصولی برای پکیج انتخاب نشده است.", 4001); } var product = _repository.Product.FindByCondition(c => c.Id == input.PackageId.Value && c.Ddate == null) .FirstOrDefault(); if (product == null) { throw new BusinessException(XError.GetDataErrors.NotFound()); } product.Name = input.Name; product.Price = input.Price; product.MetaDescription = input.MetaDesc; product.KeyWords = input.KeyWord; product.MetaTitle = input.MetaTitle; product.Mdate = DateTime.Now.Ticks; product.LanguageId = input.LanguageId; product.MuserId = ClaimPrincipalFactory.GetUserId(User); var tobeDeletedProductPackeage = _repository.ProductPackage .FindByCondition(c => c.MainProductId == product.Id).ToList(); tobeDeletedProductPackeage.ForEach(c => { c.Ddate = DateTime.Now.Ticks; c.DuserId = ClaimPrincipalFactory.GetUserId(User); }); _repository.ProductPackage.UpdateRange(tobeDeletedProductPackeage); input.ProductWithPriceList.ForEach(c => { var newProductPackage = new ProductPackage() { Cdate = DateTime.Now.Ticks, CuserId = ClaimPrincipalFactory.GetUserId(User), DepProductId = c.ProductId, Price = c.Price }; product.ProductPackageDepProduct.Add(newProductPackage); }); var tobeDeletedProductImage = _repository.ProductImage .FindByCondition(c => c.ProductId == product.Id).ToList(); tobeDeletedProductImage.ForEach(c => { c.Ddate = DateTime.Now.Ticks; c.DuserId = ClaimPrincipalFactory.GetUserId(User); }); _repository.ProductImage.UpdateRange(tobeDeletedProductImage); fileList.ForEach(c => { short fileType = 1; if (FileManeger.IsVideo(c)) { fileType = 2; } var uploadFileStatus = FileManeger.FileUploader(c, fileType, "ProductPackage"); if (uploadFileStatus.Status == 200) { var newProductImage = new ProductImage { Cdate = DateTime.Now.Ticks, CuserId = ClaimPrincipalFactory.GetUserId(User), ImageUrl = uploadFileStatus.Path, FileType = fileType }; product.ProductImage.Add(newProductImage); } else { throw new BusinessException(uploadFileStatus.Path, 4009); } }); _repository.Product.Update(product); _repository.Save(); _logger.LogData(MethodBase.GetCurrentMethod(), General.Results_.SuccessMessage(), null, input, "****"); return(Ok(General.Results_.SuccessMessage())); } catch (Exception e) { _logger.LogError(e, MethodBase.GetCurrentMethod(), input, "****"); return(BadRequest(e.Message)); } }
public IActionResult InsertPackage([FromForm] InsertPackageDto input, [FromForm] FormFileCollection fileList) { try { var validator = new ParamValidator(); validator.ValidateNull(input.Name, General.Messages_.NullInputMessages_.GeneralNullMessage("عنوان")) .ValidateNull(input.Price, General.Messages_.NullInputMessages_.GeneralNullMessage("قیمت")) .Throw(General.Results_.FieldNullErrorCode()); if (input.ProductWithPriceList.Count == 0) { throw new BusinessException("محصولی برای پکیج انتخاب نشده است.", 4001); } var counter = (_repository.Product .FindByCondition(c => c.Coding.ToString().Substring(0, 8) == "11223344") .Count() + 1).ToString(); counter = counter.PadLeft(4, '0'); var newproduct = new Product { Name = input.Name, Price = input.Price, MetaDescription = input.MetaDesc, KeyWords = input.KeyWord, MetaTitle = input.MetaTitle, Coding = long.Parse("11223344" + counter), IsPackage = true, Cdate = DateTime.Now.Ticks, CuserId = ClaimPrincipalFactory.GetUserId(User) }; input.ProductWithPriceList.ForEach(c => { var newProductPackage = new ProductPackage() { Cdate = DateTime.Now.Ticks, CuserId = ClaimPrincipalFactory.GetUserId(User), DepProductId = c.ProductId, Price = c.Price }; newproduct.ProductPackageDepProduct.Add(newProductPackage); }); fileList.ForEach(c => { short fileType = 1; if (FileManeger.IsVideo(c)) { fileType = 2; } var uploadFileStatus = FileManeger.FileUploader(c, fileType, "ProductPackage"); if (uploadFileStatus.Status == 200) { var newProductImage = new ProductImage { Cdate = DateTime.Now.Ticks, CuserId = ClaimPrincipalFactory.GetUserId(User), ImageUrl = uploadFileStatus.Path, FileType = fileType }; newproduct.ProductImage.Add(newProductImage); } else { throw new BusinessException(uploadFileStatus.Path, 4009); } }); _repository.Product.Create(newproduct); _repository.Save(); _logger.LogData(MethodBase.GetCurrentMethod(), newproduct.Id, null, input, "****"); return(Ok(newproduct.Id)); } catch (Exception e) { _logger.LogError(e, MethodBase.GetCurrentMethod(), input, "****"); return(BadRequest(e.Message)); } }
public IActionResult UpdateProductPackingList(ProductPackingListInsertDto input) { try { var validator = new ParamValidator(); validator.ValidateNull(input.Title, General.Messages_.NullInputMessages_.GeneralNullMessage("نام")) .ValidateNull(input.PackingTypeId, General.Messages_.NullInputMessages_.GeneralNullMessage("کد بسته بندی")) .ValidateNull(input.PackingTypeId, General.Messages_.NullInputMessages_.GeneralNullMessage("آیدی")) .Throw(General.Results_.FieldNullErrorCode()); var packingList = _repository.ProductPackingTypeList.FindByCondition(c => c.Id == input.Id) .FirstOrDefault(); if (packingList == null) { throw new BusinessException(XError.GetDataErrors.NotFound()); } packingList.Title = input.Title; packingList.Mdate = DateTime.Now.Ticks; packingList.MuserId = ClaimPrincipalFactory.GetUserId(User); var toBeDeleted = _repository.ProductPackingType .FindByCondition(c => c.ProductPackingTypeListId == input.Id).ToList(); toBeDeleted.ForEach(c => { c.Ddate = DateTime.Now.Ticks; c.DuserId = ClaimPrincipalFactory.GetUserId(User); }); _repository.ProductPackingType.UpdateRange(toBeDeleted); var InDbPackingType = _repository.PackingType.FindByCondition(c => c.Id == toBeDeleted.Select(c => c.PackinggTypeId).FirstOrDefault()).FirstOrDefault(); if (InDbPackingType.Id == input.PackingTypeId) { input.ProductIdList.ForEach(c => { var pp = new ProductPackingType { Cdate = DateTime.Now.Ticks, CuserId = ClaimPrincipalFactory.GetUserId(User), PackinggTypeId = input.PackingTypeId, ProductId = c, Price = InDbPackingType.Price }; packingList.ProductPackingType.Add(pp); }); } else { var packingType = _repository.PackingType.FindByCondition(c => c.Id == input.PackingTypeId && c.DaDate == null && c.Ddate == null).FirstOrDefault(); if (packingType == null || packingType.Count < 1) { throw new BusinessException(XError.BusinessErrors.InvalidPackingType()); } input.ProductIdList.ForEach(c => { var pp = new ProductPackingType { Cdate = DateTime.Now.Ticks, CuserId = ClaimPrincipalFactory.GetUserId(User), PackinggTypeId = input.PackingTypeId, ProductId = c, Price = packingType.Price }; packingList.ProductPackingType.Add(pp); }); packingType.Count -= 1; _repository.PackingType.Update(packingType); } _repository.ProductPackingTypeList.Update(packingList); _repository.Save(); _logger.LogData(MethodBase.GetCurrentMethod(), General.Results_.SuccessMessage(), null, input); return(Ok(General.Results_.SuccessMessage())); } catch (Exception e) { _logger.LogError(e, MethodBase.GetCurrentMethod(), input); return(BadRequest(e.Message)); } }
public IActionResult UpdatePackingType() { try { var packingType = JsonSerializer.Deserialize <PackingType>(HttpContext.Request.Form["PackingType"]); var validator = new ParamValidator(); validator.ValidateNull(packingType.Name, General.Messages_.NullInputMessages_.GeneralNullMessage("نام")) .ValidateNull(packingType.Price, General.Messages_.NullInputMessages_.GeneralNullMessage("قیمت")) .ValidateNull(packingType.Id, General.Messages_.NullInputMessages_.GeneralNullMessage("آیدی")); var photo = HttpContext.Request.Form.Files.GetFile("Photo"); var video = HttpContext.Request.Form.Files.GetFile("Video"); var photopath = ""; var videopath = ""; if (photo != null) { var uploadFileStatus = FileManeger.FileUploader(photo, 1, "PackingTypeImages"); if (uploadFileStatus.Status == 200) { photopath = uploadFileStatus.Path; } else { throw new BusinessException(uploadFileStatus.Path, 100); } } if (video != null) { var uploadFileStatus1 = FileManeger.FileUploader(video, 2, "PackingTypeVideo"); if (uploadFileStatus1.Status == 200) { videopath = uploadFileStatus1.Path; } else { throw new BusinessException(uploadFileStatus1.Path, 100); } } var packing = _repository.PackingType.FindByCondition(c => c.Id == packingType.Id) .Include(c => c.PackingTypeImage).FirstOrDefault(); if (packing == null) { throw new BusinessException(XError.GetDataErrors.NotFound()); } packing.MuserId = DateTime.Now.Ticks; packing.Mdate = ClaimPrincipalFactory.GetUserId(User); if (photopath != "") { var toBeDeletedImage = packing.PackingTypeImage.FirstOrDefault(c => c.FileType == 2); if (toBeDeletedImage != null) { _repository.PackingTypeImage.Delete(toBeDeletedImage); } var packingtypeImge = new PackingTypeImage { ImageFileUrl = photopath, Cdate = DateTime.Now.Ticks, CuserId = ClaimPrincipalFactory.GetUserId(User), FileType = 1 }; packing.PackingTypeImage.Add(packingtypeImge); } if (photopath != "") { var toBeDeletedVideo = packing.PackingTypeImage.FirstOrDefault(c => c.FileType == 1); if (toBeDeletedVideo != null) { _repository.PackingTypeImage.Delete(toBeDeletedVideo); } var packingtypeVideo = new PackingTypeImage { ImageFileUrl = videopath, Cdate = DateTime.Now.Ticks, CuserId = ClaimPrincipalFactory.GetUserId(User), FileType = 2 }; packing.PackingTypeImage.Add(packingtypeVideo); } _repository.PackingType.Update(packing); _repository.Save(); _logger.LogData(MethodBase.GetCurrentMethod(), packing.Id, null); return(Ok(packing.Id)); } catch (Exception e) { _logger.LogError(e, MethodBase.GetCurrentMethod()); return(BadRequest(e.Message)); } }
public IActionResult InsertPackingType() { try { var packingType = JsonSerializer.Deserialize <PackingType>(HttpContext.Request.Form["PackingType"]); var validator = new ParamValidator(); validator.ValidateNull(packingType.Name, General.Messages_.NullInputMessages_.GeneralNullMessage("نام")) .ValidateNull(packingType.Price, General.Messages_.NullInputMessages_.GeneralNullMessage("قیمت")); var photo = HttpContext.Request.Form.Files.GetFile("Photo"); var video = HttpContext.Request.Form.Files.GetFile("Video"); var photopath = ""; var videopath = ""; if (photo != null) { var uploadFileStatus = FileManeger.FileUploader(photo, 1, "PackingTypeImages"); if (uploadFileStatus.Status == 200) { photopath = uploadFileStatus.Path; } else { throw new BusinessException(uploadFileStatus.Path, 100); } } if (video != null) { var uploadFileStatus1 = FileManeger.FileUploader(video, 2, "PackingTypeVideo"); if (uploadFileStatus1.Status == 200) { videopath = uploadFileStatus1.Path; } else { throw new BusinessException(uploadFileStatus1.Path, 100); } } packingType.Cdate = DateTime.Now.Ticks; packingType.CuserId = ClaimPrincipalFactory.GetUserId(User); if (photopath != "") { var packingtypeImge = new PackingTypeImage { ImageFileUrl = photopath, Cdate = DateTime.Now.Ticks, CuserId = ClaimPrincipalFactory.GetUserId(User), FileType = 2 }; packingType.PackingTypeImage.Add(packingtypeImge); } if (photopath != "") { var packingtypeVideo = new PackingTypeImage { ImageFileUrl = videopath, Cdate = DateTime.Now.Ticks, CuserId = ClaimPrincipalFactory.GetUserId(User), FileType = 1 }; packingType.PackingTypeImage.Add(packingtypeVideo); } _repository.PackingType.Create(packingType); _repository.Save(); _logger.LogData(MethodBase.GetCurrentMethod(), packingType.Id, null); return(Ok(packingType.Id)); } catch (Exception e) { _logger.LogError(e, MethodBase.GetCurrentMethod()); return(BadRequest(e.Message)); } }
public IActionResult UpdateOffer(OfferInsertDto offerInsert) { try { var validator = new ParamValidator(); validator.ValidateNull(offerInsert.FromDate, General.Messages_.NullInputMessages_.GeneralNullMessage("از تاریخ")) .ValidateNull(offerInsert.Id, General.Messages_.NullInputMessages_.GeneralNullMessage("آیدی")) .ValidateNull(offerInsert.ToDate, General.Messages_.NullInputMessages_.GeneralNullMessage("تا تاریخ")) .ValidateNull(offerInsert.Name, General.Messages_.NullInputMessages_.GeneralNullMessage("عنوان")) .ValidateNull(offerInsert.Value, General.Messages_.NullInputMessages_.GeneralNullMessage("مقدار تخفیف")) .ValidateNull(offerInsert.MaximumPrice, General.Messages_.NullInputMessages_.GeneralNullMessage("حداکثر قیمت")) .ValidateNull(offerInsert.OfferTypeId, General.Messages_.NullInputMessages_.GeneralNullMessage("نوع تخفیف")) .ValidateNull(offerInsert.OfferCode, General.Messages_.NullInputMessages_.GeneralNullMessage("کد تخفیف")) .Throw(General.Results_.FieldNullErrorCode()); var offer = _repository.Offer.FindByCondition(c => c.Id == offerInsert.Id).FirstOrDefault(); if (offer == null) { throw new BusinessException(XError.GetDataErrors.NotFound()); } offer.Mdate = DateTime.Now.Ticks; offer.MuserId = ClaimPrincipalFactory.GetUserId(User); offer.Description = offerInsert.Description; offer.FromDate = offerInsert.FromDate?.Ticks ?? 0; offer.HaveTimer = offerInsert.HaveTimer; offer.MaximumPrice = offerInsert.MaximumPrice; offer.Name = offerInsert.Name; offer.OfferCode = offerInsert.OfferCode; offer.OfferTypeId = offerInsert.OfferTypeId; offer.ToDate = offerInsert.ToDate?.Ticks ?? 0; offer.Value = offerInsert.Value; var deletedPRoductOffer = _repository.ProductOffer.FindByCondition(c => c.OfferId == offerInsert.Id) .ToList(); deletedPRoductOffer.ForEach(c => { _repository.ProductOffer.Delete(c); }); offerInsert.ProductIdList.ForEach(c => { var productOffer = new ProductOffer { Cdate = DateTime.Now.Ticks, CuserId = ClaimPrincipalFactory.GetUserId(User), ProductId = c, Value = offerInsert.Value, FromDate = offerInsert.FromDate?.Ticks ?? 0, ToDate = offerInsert.ToDate?.Ticks ?? 0, LanguageId = offerInsert.LanguageId }; offer.ProductOffer.Add(productOffer); }); _repository.Offer.Update(offer); _repository.Save(); _logger.LogData(MethodBase.GetCurrentMethod(), General.Results_.SuccessMessage(), null, offerInsert); return(Ok(General.Results_.SuccessMessage())); } catch (Exception e) { _logger.LogError(e, MethodBase.GetCurrentMethod(), offerInsert); return(BadRequest(e.Message)); } }
/// <summary> /// Method to validate model /// </summary> /// <returns>Returns the result of validation</returns> protected override FluentValidation.Results.ValidationResult Validate() { var validator = new ParamValidator(); return(validator.Validate(this)); }
public IActionResult UpdateEmployee(EmployeeInsertDto input) { try { var user = _repository.Employee.FindByCondition(c => c.Id == input.Id).Select(c => c.User) .FirstOrDefault(); #region Validation if (user == null) { throw new BusinessException(XError.GetDataErrors.NotFound()); } var validator = new ParamValidator(); validator.ValidateNull(input.FirstName, General.Messages_.NullInputMessages_.GeneralNullMessage("نام")) .ValidateNull(input.LastName, General.Messages_.NullInputMessages_.GeneralNullMessage("نام خانوادگی")) .ValidateNull(input.UserName, General.Messages_.NullInputMessages_.GeneralNullMessage("نام کاربری")) .ValidateNull(input.Password, General.Messages_.NullInputMessages_.GeneralNullMessage("رمز عبور")) .Throw(General.Results_.FieldNullErrorCode()); if (input.RoleList.Count == 0) { throw new BusinessException(XError.BusinessErrors.RoleNotSelected()); } if (_repository.Users.FindByCondition(c => c.Username == input.UserName && c.Id != user.Id).Any()) { throw new BusinessException(XError.BusinessErrors.UserAlreadyExists()); } #endregion user.Mdate = DateTime.Now.Ticks; user.MuserId = ClaimPrincipalFactory.GetUserId(User); user.FullName = input.FirstName + " " + input.LastName; user.Hpassword = input.Password; user.Username = input.UserName; var toBeDdeleted = _repository.UserRole.FindByCondition(c => c.UserId == user.Id).ToList(); _repository.UserRole.DeleteRange(toBeDdeleted); input.RoleList.ForEach(c => { var userRole = new UserRole { Cdate = DateTime.Now.Ticks, CuserId = ClaimPrincipalFactory.GetUserId(User), Role = c }; user.UserRole.Add(userRole); }); _repository.Users.Update(user); _repository.Save(); _logger.LogData(MethodBase.GetCurrentMethod(), General.Results_.SuccessMessage(), null, input); return(Ok(General.Results_.SuccessMessage())); } catch (Exception e) { _logger.LogError(e, MethodBase.GetCurrentMethod(), input); return(BadRequest(e.Message)); } }