/// <summary> /// Gets the <see cref="Werkstatt"/> /// </summary> /// <param name="werkstatt">the <see cref="Werkstatt"/></param> /// <returns>a <see cref="Werkstatt"/></returns> private static Werkstatt GetWerkstatt(string werkstatt) { try { List <Werkstatt> lager = null; using (repository = RepositoryFactory.Instance.CreateRepository <RepositoryForSpecialDataTypes>()) { lager = new List <Werkstatt>(repository.SelectMany <Werkstatt>().AsEnumerable()); } Werkstatt w = lager.Find(item => item.Standort.Equals(werkstatt)); AddCoordinates <Werkstatt>(new List <Werkstatt>() { w }, "koordinaten", "Standort"); return(w); } catch (DatabaseException) { throw; } catch (Exception ex) { throw (new DatabaseException(ex, "Error in selecting all autoteile ")); } }
/// <summary> /// Gets a json string containing the coordinates of the given list of <see cref="LagerverwaltungBL.Model.Zentrallager"/> and <see cref="LagerverwaltungBL.Model.Werkstatt"/> /// </summary> /// <param name="lager">the list of <see cref="Zentrallager"/></param> /// <param name="werkstatt">the <see cref="Werkstatt.Standort"/></param> /// <returns>string for two javascript variable containing the array /// of lager coordinates and the coordinates of the werkstatt /// </returns> public static string GetJsonCoordinates(List <Zentrallager> lager, string werkstatt) { string ret = string.Empty; object[] arr = lager.Where(item => item.Coordinates != null).Select(item => new { name = item.Standort, coordinates = new { lat = item.Coordinates.X, lng = item.Coordinates.Y } }).ToArray(); string s = string.Format("var lagerCoords = JSON.parse('{0}');", JsonConvert.SerializeObject(arr, Formatting.None)); Werkstatt w = GetWerkstatt(werkstatt); object toSer = new { name = w.Standort, coordinates = new { lat = w.Coordinates.X, lng = w.Coordinates.Y } }; s += string.Format(" var werkstatt = JSON.parse('{0}');", JsonConvert.SerializeObject(toSer, Formatting.None)); return(s); }
/// <summary> /// Orders a <see cref="Autoteile"/> to the given <see cref="Werkstatt"/> /// updates the inventory /// creates a new <see cref="Werkstattlager"/> if it has not already been existing /// </summary> /// <param name="bezeichnung">the <see cref="Autoteile.Bezeichnung"/> of the <see cref="Autoteile"/></param> /// <param name="werkstatt">the unique <see cref="Werkstatt.Standort"/> of the <see cref="Werkstatt"/></param> /// <param name="zentrallager">the unique <see cref="Zentrallager.Standort"/> of the <see cref="Zentrallager"/></param> /// <param name="quantity">the quantity</param> /// <returns>true if everything has been ok</returns> public static bool Order(string bezeichnung, string werkstatt, string zentrallager, int quantity) { Werkstattlager lager = null; try { using (IRepository repository = RepositoryFactory.Instance.CreateRepository <Repository>()) { long count = repository.CountWhere <Werkstattlager>(DetachedCriteria.For <Werkstattlager>() .Add(Restrictions.Where <Werkstattlager>(item => item.Werkstatt.Standort == (werkstatt))) .Add(Restrictions.Where <Werkstattlager>(item => item.Teil.Bezeichnung == (bezeichnung)))); if (count > 0) { lager = repository.SelectSingleWhere <Werkstattlager>(item => item.Werkstatt.Standort.Equals(werkstatt) && item.Teil.Bezeichnung.Equals(bezeichnung)); lager.Bestand += quantity; } else { Werkstatt w = repository.SelectSingleWhere <Werkstatt>(item => item.Standort.Equals(werkstatt)); Autoteile a = repository.SelectSingleWhere <Autoteile>(item => item.Bezeichnung.Equals(bezeichnung)); lager = new Werkstattlager() { Werkstatt = w, Teil = a, Bestand = quantity }; } repository.SaveOrUpdate <Werkstattlager>(lager); } return(true); } catch (DatabaseException) { throw; } catch (Exception ex) { throw (new DatabaseException(ex, "Error at ordering")); } }