static private void readFile(string file, ArrayList list, ArrayList fields) { try { using (StreamReader sr = new StreamReader(file)) { String line = sr.ReadLine(); var stringFIelds = readingFields(line, ','); convertTabToArray(fields, stringFIelds); while ((line = sr.ReadLine()) != null) { DataCustomer dataObj = new DataCustomer(); if (line.Length > 0) { var values = readingFields(line, ','); insertingValues(dataObj, fields, values); list.Add(dataObj); } } sr.Close(); } } catch (Exception e) { Console.WriteLine("Error: " + e); } }
private static void insertingValues(DataCustomer data, ArrayList field, string[] value) { for (int i = 0; i < field.Count; i++) { selectFunction(field[i].ToString(), value[i], data); } }
/// <summary> /// Updates an existing user with info from a NAS member from Visma. /// </summary> /// <returns> /// <c>True</c> if the update was successful. /// </returns> /// <param name="innUser">NAS member from Visma</param> /// <param name="membership">Type of membership determined in the BLL</param> public bool UpdateUserFromVisma(DataCustomer innUser, string membership) { try { // Gets the user to be edited from the user table var editUser = _db.UserTable.FirstOrDefault(d => d.UserId == innUser.Id.ToString()); // Sets the fields from the Customer to user to be updated in the user table. editUser.Username = innUser.EmailAddress; editUser.Name = innUser.Name; editUser.Membership = membership; _db.SaveChanges(); return(true); } catch (Exception e) { // Creates a new error filer object var errorLog = new ErrorFiler(); // Logs the error to the error log, with the name of the exception and where it occured errorLog.WriteError(e.GetType().FullName, "NasDAL, bool UpdateUserFromVisma(DataCustomer innUser, string membership)"); return(false); } }
/// <summary> /// Turns a view model user into database model user and adds in to the user table in the database. /// </summary> /// <returns> /// <c>True</c> if the adding was successful. /// </returns> /// <param name="customer">User from Visma to be added to the database.</param> /// <param name="membership">Type of membership the customer has.</param> public bool AddUser(DataCustomer customer, string membership) { try { var newUser = new User() { UserId = customer.Id.ToString(), Name = customer.Name, Username = customer.EmailAddress, Membership = membership }; _db.UserTable.Add(newUser); _db.SaveChanges(); return(true); } catch (Exception e) { // Creates a new error filer object var errorLog = new ErrorFiler(); // Logs the error to the error log, with the name of the exception and where it occured errorLog.WriteError(e.GetType().FullName, "NasDAL, bool AddUser(DataCustomer customer, string membership)"); return(false); } }
/// <summary> /// The Save method adds the Customer (this) object to the internal data structure. /// </summary> public void Save() { if (this.customerID > 0) { DataCustomer.Update(this); } else { this.customerID = DataCustomer.Add(this); } }
public bool CreateCustomer(DataCustomer customer) { try { _context.Customer.Add(customer); _context.SaveChanges(); return(true); } catch (Exception e) { return(false); } }
private static void compareValues(ArrayList dataFile1, ArrayList dataFile2) { ArrayList tmp = new ArrayList(); float flag = -1; ArrayList indexTab = new ArrayList(); IComparer comp = new myComparer(); foreach (DataCustomer data1 in dataFile1) { foreach (DataCustomer data2 in dataFile2) { if (data1.getCustomer() == data2.getCustomer() && data1.getProduct() == data2.getProduct()) { DataCustomer tmpData = new DataCustomer(data1); indexTab.Add(dataFile2.IndexOf(data2)); if (data2.getPrice() != flag) { tmpData.setPrice((float)data2.getPrice()); } if (data2.getAmount() != flag) { tmpData.setAmount(data2.getAmount()); } if ((float)data2.getQuantity() != flag) { tmpData.setQuantity(data2.getQuantity()); } if ((float)data2.getInvoice() != flag) { tmpData.setInvoice(data2.getInvoice()); } if (data2.getCost() != flag) { tmpData.setCost(data2.getCost()); } tmp.Add(tmpData); } } } removeFromArrayAtInexes(dataFile2, indexTab); dataFile1.Clear(); addArrayList(dataFile1, tmp); addArrayList(dataFile1, dataFile2); dataFile1.Sort(comp); }
public DataCustomer GetCustomer(string customerId) { DataCustomer customer = new DataCustomer(); try { return(_context.Customer.Where(x => x.CustomerId == customerId).Select(x => new DataCustomer() { CustomerId = x.CustomerId, Name = x.Name, Addresses = _context.Address.Where(y => y.CustomerId == x.CustomerId).ToList() }).First()); } catch (Exception e) { return(null); } }
public void TestInsertCustomer() { Customer customer = new Customer() { FirstName = "Bobby", LastName = "Olsen", Street = "Cykelvænget", HouseNo = 8, ZipCode = "9000", Email = "*****@*****.**", PhoneNumber = "88888888", Password = "******" }; Assert.IsTrue(cs.AddCustomer(customer)); // Delete the customer from the database again DataCustomer db = new DataCustomer(); db.DeleteCustomerTestingPurpose(); }
private static void selectFunction(string field, string value, DataCustomer data) { int precision = 10; switch (field) { case "Customer": data.setCustomer(value.Trim()); break; case "Product": data.setProduct(value.Trim()); break; case "Price": data.setPrice(roundDigits(value, precision)); break; case "Quantity": data.setQuantity(Int32.Parse(value)); break; case "Cost": data.setCost(roundDigits(value, precision)); break; case "Total Amount": data.setAmount(roundDigits(value, precision)); break; case "Invoice Number": data.setInvoice(Int32.Parse(value)); break; default: Console.WriteLine("Unknown field"); break; } }
public bool CreateCustomer(Customer customer) { DataCustomer dataCustomer = _mapper.Map <Customer, DataCustomer>(customer); return(repo.CreateCustomer(dataCustomer)); }
public bool UpdateUserFromVisma(DataCustomer user, string membership) { throw new NotImplementedException(); }
//tutaj private static string builderLine(DataCustomer data, ArrayList fields) { string flagS = "none"; float flag = -1; StringBuilder sb = new StringBuilder(); for (int i = 0; i < fields.Count; i++) { switch (fields[i]) { case "Customer": if (data.getCustomer() != flagS) { sb.Append(data.getCustomer() + ","); } else { sb.Append(","); } break; case "Product": if (data.getProduct() != flagS) { sb.Append(data.getProduct() + ","); } else { sb.Append(","); } break; case "Price": if (data.getPrice() != flag) { sb.Append(data.getPrice() + ","); } else { sb.Append(","); } break; case "Quantity": if (data.getQuantity() != flag) { sb.Append(data.getQuantity() + ","); } else { sb.Append(","); } break; case "Cost": if (data.getCost() != flag) { sb.Append(data.getCost() + ","); } else { sb.Append(","); } break; case "Total Amount": if (data.getAmount() != flag) { sb.Append(data.getAmount() + ","); } else { sb.Append(","); } break; case "Invoice Number": if (data.getInvoice() != flag) { sb.Append(data.getInvoice() + ","); } else { sb.Append(","); } break; default: Console.WriteLine("BUilder line Unknown field" + fields[i]); break; } } return(sb.ToString()); }
public bool AddUser(DataCustomer customer, string membership) { throw new NotImplementedException(); }
/// <summary> /// The static Add method interacts with the DataLayer in order to /// add a received object to the internal structure. /// </summary> /// <param name="transaction">The Customer object that you want to add</param> public static void Add(Customer customer) { DataCustomer.Add(customer); }
/// <summary> /// The static Fetch method interacts with the DataLayer /// in order to retrieve a object which corresponds to the ID key received. /// </summary> /// <param name="id">The ID key of the object</param> /// <returns>The object found matching the key.</returns> public static Customer Fetch(int id) { return(DataCustomer.Fetch(id)); }
public Customer CustomerLogin(string email, string password) { DataCustomer customerDB = new DataCustomer(); return(customerDB.CustomerLogin(email, password)); }
/// <summary> /// The static Remove method interacts with the DataLayer in order to /// remove a object corresponding to the received ID key. /// </summary> /// <param name="id">The ID key corresponding to the object that you want removed</param> public static Boolean Remove(int id) { return(DataCustomer.Remove(id)); }
public Customer GetCustomer(int id) { DataCustomer customerDb = new DataCustomer(); return(customerDb.getCustomer(id)); }
public bool InsertCustomer(Customer customerToInsert) { DataCustomer customerDb = new DataCustomer(); return(customerDb.SaveCustomer(customerToInsert)); }
/// <summary> /// The List method gets the list of objects from the Data Layer. /// </summary> /// <returns>List of Customer objects</returns> public static List <Customer> List() { return(DataCustomer.List()); }
/// <summary> /// Determines the type of membership the user has from customer details from Visma. /// </summary> /// <returns> /// A <c>string</c> containing the type of membership the user has. /// </returns> /// <para> The method is used to turn 11 types of membership from Visma into 4 types to be displayed in the mobile app.</para> /// <param name="customer">A user gotten from the Visma eAccounting API.</param> public string DetermineMembership(DataCustomer customer) { string membership = "Ikke aktivt medlemskap"; try { // Iterates through the list of customer labes from a member in Visma and determines what membership the user has. foreach (var label in customer.CustomerLabels) { switch (label.Name) { case "Enkeltmedlemskap": membership = "Enkeltmedlemskap"; break; case "vikingredaksjonen": membership = "Enkeltmedlemskap"; break; case "sekretær enkeltmedlem": membership = "Enkeltmedlemskap"; break; case "enkeltmedlem uten epost": membership = "Enkeltmedlemskap"; break; case "utland enkeltmedlem": membership = "Enkeltmedlemskap"; break; case "støttemedlem": membership = "Enkeltmedlemskap"; break; case "Familiemedlemskap": membership = "Familiemedlemskap"; break; case "Familiemedlemskap 2": membership = "Familiemedlemskap"; break; case "Studentmedlemskap": membership = "Studentmedlemskap"; break; case "Studentrepresentant": membership = "Studentmedlemskap"; break; case "Livsvarig": membership = "Livsvarig"; break; } } } catch (Exception e) { // Creates a new error filer object var errorLog = new ErrorFiler(); // Logs the error to the error log, with the name of the exception and where it occured errorLog.WriteError(e.GetType().FullName, "NasBLL, string DetermineMembership(DataCustomer customer)"); } return(membership); }
public CustomerControl() { dataCustomer = new DataCustomer(); }