Exemplo n.º 1
0
 internal void AddToCatalog(int caseId, AskingPrice askingPrice)
 {
     if (!askingPriceDictionary.ContainsKey(caseId))
     {
         askingPriceDictionary.Add(caseId, new List <AskingPrice>());
     }
     if (!askingPriceDictionary[caseId].Contains(askingPrice))
     {
         askingPriceDictionary[caseId].Add(askingPrice);
     }
 }
Exemplo n.º 2
0
 internal void Save(AskingPrice askingPrice, int caseId)
 {
     if (askingPrice.Id == -1)
     {
         askingPrice.Id = db.CreateAskingPrice(askingPrice, caseId);
     }
     else
     {
         db.UpdateAskingPrice(askingPrice, caseId);
     }
 }
Exemplo n.º 3
0
        /// <summary>
        /// Creates an AskingPrice in the database.
        /// </summary>
        /// <param name="askingPrice">AskingPrice to be created.</param>
        /// <param name="caseId">CaseId connected to the AskingPrice</param>
        /// <returns>Returns the Id of the AskingPrice created.</returns>
        /// <author>René Sørensen</author>
        public int CreateAskingPrice(AskingPrice askingPrice, int caseId)
        {
            SqlCommand cmd = new SqlCommand
            {
                CommandText = "INSERT INTO AskingPrice OUTPUT INSERTED.AskingPriceId VALUES (@CaseId, @Value, @Date); "
            };

            cmd.Parameters.Add("@CaseId", SqlDbType.Int, 4, "caseId").Value  = caseId;
            cmd.Parameters.Add("@Value", SqlDbType.BigInt, 8, "Value").Value = askingPrice.Value;
            cmd.Parameters.Add("@Date", SqlDbType.Date, 8, "Date").Value     = askingPrice.Date;

            return((int)DBConnectionMSSQL.Instance.ExecuteScalar(cmd, -1));
        }
Exemplo n.º 4
0
        /// <summary>
        /// Updates the information from an AskingPrice, in the database.
        /// </summary>
        /// <param name="askingPrice">AskingPrice to be updated.</param>
        /// <param name="caseId">CaseId connected to the appointment</param>
        /// <author>René Sørensen</author>
        public void UpdateAskingPrice(AskingPrice askingPrice, int caseId)
        {
            int askingPriceId = askingPrice.Id;

            SqlCommand cmd = new SqlCommand
            {
                CommandText = "UPDATE AskingPrice SET CaseId = (@CaseId), Value = (@Value), Date = (@Date)" + "WHERE AskingPriceId = (@AskingPriceId)"
            };

            cmd.Parameters.Add("@AskingPriceId", SqlDbType.Int, 4, "AskingPriceId").Value = askingPriceId;

            cmd.Parameters.Add("@CaseId", SqlDbType.Int, 4, "caseId").Value  = caseId;
            cmd.Parameters.Add("@Value", SqlDbType.BigInt, 8, "Value").Value = askingPrice.Value;
            cmd.Parameters.Add("@Date", SqlDbType.Date, 8, "Date").Value     = askingPrice.Date;

            DBConnectionMSSQL.Instance.ExecuteNonQuery(cmd);
        }
Exemplo n.º 5
0
        /// <summary>
        /// Returns a dictionary containing all the AskingPrices in the database.
        /// </summary>
        /// <returns>Returns a dictionary containing all the AskingPrices in the database, with CaseId as key and a list of AskingPrices containing that caseId</returns>
        /// <author>René Sørensen</author>
        public Dictionary <int, List <AskingPrice> > ReadAskingPrices()
        {
            Dictionary <int, List <AskingPrice> > askingPriceList = new Dictionary <int, List <AskingPrice> >();

            SqlCommand cmd = new SqlCommand
            {
                CommandText = "SELECT * FROM AskingPrice ORDER BY Date ASC;",
            };

            SqlDataReader reader = null;

            try
            {
                reader = DBConnectionMSSQL.Instance.ExecuteReader(cmd);
                while (reader.Read())
                {
                    int      askingPriceId = (int)reader["AskingPriceId"];
                    int      caseId        = (int)reader["CaseId"];
                    long     value         = (long)reader["Value"];
                    DateTime date          = (DateTime)reader["Date"];

                    AskingPrice askingPrice = new AskingPrice(askingPriceId, value, date);
                    if (!askingPriceList.ContainsKey(caseId))
                    {
                        askingPriceList.Add(caseId, new List <AskingPrice>());
                    }

                    askingPriceList[caseId].Add(askingPrice);
                }
            }
            catch (SqlException e)
            {
                Console.WriteLine(e.Message);
            }
            finally
            {
                if (reader != null)
                {
                    reader.Close();
                }
            }

            return(askingPriceList);
        }
Exemplo n.º 6
0
 /// <summary>
 /// Fjerner en udbudspris fra casen
 /// </summary>
 /// <author>Mathias Poulsen</author>
 public void RemoveAskingPriceFromCase(AskingPrice askingPrice)
 {
     askingPriceCatalog.RemoveFromCatalog(activeCase.Id, askingPrice);
 }
Exemplo n.º 7
0
 /// <summary>
 /// Tilføjer en udbudspris til casen
 /// </summary>
 /// <param name="askingPrice"></param>
 /// <author>Mathias Poulsen</author>
 private void AddAskingPriceToCase(AskingPrice askingPrice)
 {
     askingPriceCatalog.AddToCatalog(activeCase.Id, askingPrice);
 }
Exemplo n.º 8
0
 /// <summary>
 /// Laver en ny udbudspris
 /// </summary>
 /// <param name="value"></param>
 /// <returns></returns>
 /// <author>Mathias Petersen</author>
 public AskingPrice MakeNewAskingPrice(long value)
 {
     tempAskingPrice = new AskingPrice(value);
     return(tempAskingPrice);
 }
Exemplo n.º 9
0
 internal void RemoveFromCatalog(int caseId, AskingPrice askingPrice)
 {
     askingPriceDictionary[caseId].Remove(askingPrice);
 }