public static FranchiseIncomeReq AddNewFranchise(FranchiseIncomeReq req) { try { var Id = Guid.NewGuid(); FranchiseIncomeReq _frq = null; // Open connection to the database string ConnectionString = _connection; con = new SqlConnection(ConnectionString); con.Open(); string CommandText = "INSERT INTO dbo.FranchiseIncomes (ID,UserID,FranchiseIncomeID,TotalAmount,Income,CreatedOn)" + "VALUES ('" + Id + "','" + req.Pins + "','" + req.FrenchiseIncomeTypeID + "','" + req.Amount + "','" + req.Amount + "','" + DateTime.Now + "') "; cmd = new SqlCommand(CommandText); cmd.Connection = con; return(_frq); } catch (Exception ex) { Console.Write(ex.Message); return(new FranchiseIncomeReq()); } finally { // Close data reader object and database connection if (rdr != null) { rdr.Close(); } if (con.State == ConnectionState.Open) { con.Close(); } } }
public IActionResult AddFranchise(FranchiseIncomeReq oFranchise) { if (oFranchise.FrenchiseIncomeTypeID != 0) { //_franchiseIncomeRepository var _response = _franchiseUtilities.AddNewFrenchise(oFranchise); _franchiseIncomeRepository.Add(_response); GenratePins(_response, oFranchise); // _franchiseUtilities.CreateNewFrenchisePins(_userPinRepository, oFranchise, _response.ID, _response.UserID); } return(View()); }
private void GenratePins(FranchiseIncome franchiseIncome, FranchiseIncomeReq model) { var _totalPins = model.Pins + model.FreePins; for (int i = 0; i < _totalPins; i++) { var _userPin = new UserPin(); _userPin.ID = Guid.NewGuid(); _userPin.FranchiseIncomeID = franchiseIncome.ID.ToString(); _userPin.Pin = _franchiseUtilities.GetRandomPin(); _userPin.IsUsed = false; _userPin.CreatedOn = DateTime.Now; _userPinRepository.Add(_userPin); } }
public static List <FranchiseIncomeReq> GetAllFranchiseIncomeType(Guid userID) { var _franchiseIncomeTypeList = new List <FranchiseIncomeReq>(); try { SqlConnection con = new SqlConnection(_connection); SqlCommand cmd = new SqlCommand(); cmd.CommandType = CommandType.StoredProcedure; cmd.CommandText = "sp_getFranchiseIncomes"; cmd.Parameters.Add("@userID", SqlDbType.UniqueIdentifier).Value = userID; cmd.Connection = con; con.Open(); // Execute the query rdr = cmd.ExecuteReader(); while (rdr.Read()) { FranchiseIncomeReq _fit = new FranchiseIncomeReq(); _fit.Pins = Convert.ToInt32(rdr["Pins"].ToString()); _fit.FreePins = Convert.ToInt32(rdr["FreePins"].ToString()); _fit.Amount = Convert.ToDecimal(rdr["TotalAmount"].ToString()); _fit.ID = rdr["ID"].ToString(); _fit.IsActive = Convert.ToBoolean(rdr["IsActive"].ToString()); _franchiseIncomeTypeList.Add(_fit); } } catch (Exception ex) { Console.Write(ex.Message); } finally { // Close data reader object and database connection if (rdr != null) { rdr.Close(); } //if (con.State == ConnectionState.Open) //con.Close(); } return(_franchiseIncomeTypeList); }
public static FranchiseIncomeReq FindFranchiseIncomeTypeByPin(int oPin) { try { FranchiseIncomeReq _frq = null; // Open connection to the database string ConnectionString = _connection; con = new SqlConnection(ConnectionString); con.Open(); string CommandText = "SELECT * FROM FranchiseIncomeTypes where Pins = '" + oPin + "'"; cmd = new SqlCommand(CommandText); cmd.Connection = con; // Execute the query rdr = cmd.ExecuteReader(); while (rdr.Read()) { _frq = new FranchiseIncomeReq(); _frq.FrenchiseIncomeTypeID = Convert.ToInt32(rdr["FranchiseIncomeTypeID"].ToString()); _frq.Pins = Convert.ToInt32(rdr["Pins"].ToString()); _frq.FreePins = Convert.ToInt32(rdr["FreePins"].ToString()); _frq.Amount = Convert.ToDecimal(rdr["Amount"].ToString()); } return(_frq); } catch (Exception ex) { Console.Write(ex.Message); return(new FranchiseIncomeReq()); } finally { // Close data reader object and database connection if (rdr != null) { rdr.Close(); } if (con.State == ConnectionState.Open) { con.Close(); } } }
public FranchiseIncome AddNewFrenchise(FranchiseIncomeReq model) { var _ID = Guid.NewGuid(); var _oData = _franchiseIncomeRepository.Get(_ID); if (_oData == null) { var _frenchiseIncome = new FranchiseIncome(); _frenchiseIncome.ID = _ID; _frenchiseIncome.UserID = Guid.Parse(model.UserID); _frenchiseIncome.FranchiseIncomeTypeID = model.FrenchiseIncomeTypeID; _frenchiseIncome.TotalAmount = model.Amount; _frenchiseIncome.Income = model.Amount; _frenchiseIncome.CreatedOn = DateTime.Now; _frenchiseIncome.IsActive = false; _franchiseIncomeRepository.Add(_frenchiseIncome); _unitOfWork.Commit(); } return(_oData); }
public void CreateNewFrenchisePins(IBaseRepository <UserPin> userPinRepository, FranchiseIncomeReq model, Guid FranchiseIncomeID, Guid UserID) { var _totalPins = model.Pins + model.FreePins; for (int i = 0; i <= _totalPins; i++) { var _userPin = new UserPin(); _userPin.ID = Guid.NewGuid(); _userPin.FranchiseIncomeID = FranchiseIncomeID.ToString(); _userPin.UserID = string.Empty; _userPin.Pin = GetRandomPin(); _userPin.IsUsed = false; _userPin.CreatedOn = DateTime.Now; userPinRepository.Add(_userPin); } }