public ProductEN ReadOIDDefault(int productId) { ProductEN productEN = null; try { SessionInitializeTransaction(); productEN = (ProductEN)session.Get(typeof(ProductEN), productId); SessionCommit(); } catch (Exception ex) { SessionRollBack(); if (ex is P2GenNHibernate.Exceptions.ModelException) { throw ex; } throw new P2GenNHibernate.Exceptions.DataLayerException("Error in ProductCAD.", ex); } finally { SessionClose(); } return(productEN); }
public void Delete(int productId) { try { SessionInitializeTransaction(); ProductEN productEN = (ProductEN)session.Load(typeof(ProductEN), productId); session.Delete(productEN); SessionCommit(); } catch (Exception ex) { SessionRollBack(); if (ex is P2GenNHibernate.Exceptions.ModelException) { throw ex; } throw new P2GenNHibernate.Exceptions.DataLayerException("Error in ProductCAD.", ex); } finally { SessionClose(); } }
public int Create(ProductEN product) { try { SessionInitializeTransaction(); session.Save(product); SessionCommit(); } catch (Exception ex) { SessionRollBack(); if (ex is P2GenNHibernate.Exceptions.ModelException) { throw ex; } throw new P2GenNHibernate.Exceptions.DataLayerException("Error in ProductCAD.", ex); } finally { SessionClose(); } return(product.ProductId); }
public void DecreaseStock(int p_oid, int stockdown) { /*PROTECTED REGION ID(P2GenNHibernate.CEN.Default__Product_decreaseStock) ENABLED START*/ // Write here your custom code... ProductEN producto = _IProductCAD.ReadOIDDefault(p_oid); producto.Stock -= stockdown; _IProductCAD.Modify(producto); throw new NotImplementedException("Method DecreaseStock() not yet implemented."); /*PROTECTED REGION END*/ }
private bool UpdateUserBagsRefund(ProductEN pProduct, List <PersonBagOperatorEN> pPersonBags, int pPersonID) { bool finished = false; int counter = 0; var Operator = ""; try { var empty = pPersonBags.SingleOrDefault(e => e.MobileOperatorID <= 0); pPersonBags.Remove(empty); counter = pPersonBags.Count; var contador = 0; foreach (var item in pPersonBags) { if (contador == 0) { Operator = item.MobileOperatorID.ToString(); } else { Operator = Operator + "," + item.MobileOperatorID.ToString(); } contador++; #region Logs EventViewerLogger.LogInformation(String.Format("UpdateUserBags: Current User Bag: {0}, Operator: {1}, PersonID: {2}", item.UserBalance, item.MobileOperatorName, Convert.ToString(pPersonID))); #endregion } // Decimal newAmount = (!pIsRefund) ? item.UserBalanceAmount - pProduct.PersonDiscount : item.UserBalanceAmount + pProduct.PersonDiscount; int result = topupDAL.UpdateUserBagRefund(pProduct.PersonDiscount, pPersonID, Operator, counter); if (result > 1) { finished = true; } else { finished = false; } } catch (Exception ex) { Console.WriteLine(ex.InnerException); EventViewerLogger.LogError("UpdateUserBags: " + ex.Message); } return(finished); }
public void Modify(int p_oid, string p_name, string p_descripcion, string p_photoURL, float p_price, int p_stock) { ProductEN productEN = null; //Initialized ProductEN productEN = new ProductEN(); productEN.ProductId = p_oid; productEN.Name = p_name; productEN.Descripcion = p_descripcion; productEN.PhotoURL = p_photoURL; productEN.Price = p_price; productEN.Stock = p_stock; //Call to ProductCAD _IProductCAD.Modify(productEN); }
public void Modify(ProductEN product) { try { SessionInitializeTransaction(); ProductEN productEN = (ProductEN)session.Load(typeof(ProductEN), product.ProductId); productEN.Name = product.Name; productEN.Descripcion = product.Descripcion; productEN.PhotoURL = product.PhotoURL; productEN.Price = product.Price; productEN.Stock = product.Stock; session.Update(productEN); SessionCommit(); } catch (Exception ex) { SessionRollBack(); if (ex is P2GenNHibernate.Exceptions.ModelException) { throw ex; } throw new P2GenNHibernate.Exceptions.DataLayerException("Error in ProductCAD.", ex); } finally { SessionClose(); } }
public int Create(int p_productId, string p_name, string p_descripcion, string p_photoURL, float p_price, int p_stock) { ProductEN productEN = null; int oid; //Initialized ProductEN productEN = new ProductEN(); productEN.ProductId = p_productId; productEN.Name = p_name; productEN.Descripcion = p_descripcion; productEN.PhotoURL = p_photoURL; productEN.Price = p_price; productEN.Stock = p_stock; //Call to ProductCAD oid = _IProductCAD.Create(productEN); return(oid); }
public ProductEN GetAvailableTopupProduct(string pOperatorName, int pCountryID, decimal pAmount, int pPackCode) { ProductEN topupProduct = new ProductEN(); try { connection.Cnn.Open(); topupProduct = connection.Cnn.Query <ProductEN>("SpGetAvailableOperatorProduct", new { @operatorName = pOperatorName, @countryID = pCountryID, @amount = pAmount, @packCode = pPackCode }, commandType: CommandType.StoredProcedure).FirstOrDefault(); } catch (Exception ex) { topupProduct = null; Console.WriteLine(ex.Message); EventViewerLogger.LogError("GetAvailableTopupProduct: " + ex.Message); } finally { connection.Cnn.Close(); } return(topupProduct); }
public TopupTransactionEN SendTopup(PersonEN pPerson, string pOperatorName, decimal pAmount, string pPhone, int pPackCode) { TopupTransactionEN topupResult = new TopupTransactionEN(); TopupEN topup = new TopupEN(); ProductEN product = new ProductEN(); topup.Operator = pOperatorName; topup.Amount = pAmount; topup.Phone = pPhone; topup.PackageCode = pPackCode; try { var topupData = ValidateTopupData(pPerson, topup, ref product); if (topupData.IsValid) { List <PersonBagOperatorEN> operatorUserBags = topupDAL.GetUserOperatorBags(pPerson.PersonID); //Register initial bags state // var states = RegisterInitialUserBagState(operatorUserBags, product.ProductID); try { //Discounts product amount from user's bag if (UpdateUserBags(product, operatorUserBags, pPerson.PersonID)) { #region AzureSearch //if (!azureSearch.CheckExistingEntry(topupData.Phone)) // azureSearch.InsertEntry(pPerson.PersonID, pOperatorName, pPhone, pPerson.CountryID); //else // azureSearch.ComparePhoneNumber(pPhone, pOperatorName, pPerson.PersonID, pPerson.CountryID); #endregion //Gets response from Topup Service topupResult = topupClient.AttemptSendTopup(pPhone, pAmount, pPackCode, topupData.OperatorID, topupData.CategoryID); GatsTransactionEN transaction = new GatsTransactionEN(); transaction.Request = topupResult.RequestURL; transaction.Response = topupResult.Response; transaction.TransactionID = topupResult.ServiceTransactionID; transaction.ProviderTransactionID = topupResult.ServiceTransactionID; transaction.Amount = pAmount; transaction.CountryID = pPerson.CountryID; transaction.PhoneNumber = long.Parse(pPhone.ToString()); transaction.RegDate = DateTime.Now; transaction.ResponseCode = topupResult.Code; transaction.Paid = true; if (!String.Equals(topupResult.Code, "Success") && !String.Equals(topupResult.Code, "02")) { if (product.PersonDiscount > 0) { //Refunds user balance from updated values var updatedBags = topupDAL.GetUserOperatorBags(pPerson.PersonID); UpdateUserBagsRefund(product, updatedBags, pPerson.PersonID); } } else { topupResult.Message = topupData.Result; } //Updates users bags history //RegisterFinalUserBagState(states, pPerson.PersonID); topupDAL.LogTopupTransaction(transaction, pPerson.PersonID, pPerson.CountryID, topupData.Operator, product.InventoryDiscount, product.PersonDiscount); EventViewerLogger.LogInformation("SendTopup: " + transaction.Response); } } catch (Exception ex) { topupResult.Message = ex.Message; topupResult.Code = "Error"; if (product.PersonDiscount > 0) { //Gets user bags with updated values operatorUserBags = topupDAL.GetUserOperatorBags(pPerson.PersonID); //Refunds user bag if any exception ocurred UpdateUserBagsRefund(product, operatorUserBags, pPerson.PersonID); EventViewerLogger.LogError(String.Format("SendTopup - Inner exception: Refund user bags. PersonID {0}. Amount {1}. Message: {2}", Convert.ToString(pPerson.PersonID), product.PersonDiscount, ex.Message)); //Updates users bags history //RegisterFinalUserBagState(states, pPerson.PersonID); } } } else { //Sets the results according to topup data validation topupResult.Message = topupData.Result; topupResult.Code = topupData.Result; } } catch (Exception ex) { Console.WriteLine(ex.InnerException); EventViewerLogger.LogError("SendTopup: " + ex.Message); } return(topupResult); }
/// <summary> /// Validates topup requested data is correct. Checks the product selected is available for the mobile operator. /// Validates amount requested over user's bags /// </summary> /// <param name="pPerson">Vendor</param> /// <param name="pTopupData">Topup info (phone, amount, operator, etc)</param> /// <returns>Topup data result</returns> private TopupEN ValidateTopupData(PersonEN pPerson, TopupEN pTopupData, ref ProductEN oProduct) { ProductEN productAvailable = new ProductEN(); TopupEN validTopup = new TopupEN(); validTopup.IsValid = false; validTopup.PersonID = pPerson.PersonID; try { //Checks available topup product productAvailable = topupDAL.GetAvailableTopupProduct(pTopupData.Operator, pPerson.CountryID, pTopupData.Amount, pTopupData.PackageCode); if (productAvailable != null) { //Product selected for transaction oProduct = productAvailable; //Validates if user balance is required for transaction if (productAvailable.PersonDiscount > 0) { //Checks user's bags balance Decimal balance = topupDAL.GetPersonAvailableAmount(pPerson.PersonID, pPerson.CountryID, pTopupData.Operator); if (balance > 0) { if (balance >= productAvailable.PersonDiscount) { validTopup.Operator = productAvailable.OperatorName; validTopup.Product = productAvailable; validTopup.IsValid = true; validTopup.Result = Values.Ok; validTopup.ResultCode = Values.OkCode; validTopup.OperatorID = productAvailable.OperatorID; validTopup.CategoryID = productAvailable.CategoryID; } else { validTopup.Operator = productAvailable.OperatorName; validTopup.IsValid = false; validTopup.Result = Values.NoCreditLeft; validTopup.ResultCode = Values.NoCreditLeftCode; } } else { validTopup.Operator = productAvailable.OperatorName; validTopup.IsValid = false; validTopup.Result = Values.NoCreditLeft; validTopup.ResultCode = Values.NoCreditLeftCode; } } else { //Balance on user bag is not required validTopup.Operator = productAvailable.OperatorName; validTopup.IsValid = true; validTopup.Result = Values.Ok; validTopup.ResultCode = Values.PackageTopupCode; } } else { validTopup.Operator = pTopupData.Operator; validTopup.IsValid = false; validTopup.Result = Values.InvalidProduct; validTopup.ResultCode = Values.InvalidProductCode; } } catch (Exception ex) { Console.WriteLine(ex.InnerException); EventViewerLogger.LogError("ValidateTopupData: " + ex.Message); } return(validTopup); }