/// <summary> /// Erases a hosting unit /// </summary> /// <param name="hostUnit"></param> public void Erase_Hosting_Unit(HostingUnit hostUnit) { List <Order> ordersList = Dal.Get_Order_List(); foreach (var order in ordersList) { if (order.HostingUnitKey == hostUnit.HostingUnitKey) { if (order.Status == Order_Status.Mail_Sent) { throw new Can_tEraseException("Can't erase the hosting unit.There is an order connected to it ! From BL"); } } } try { Dal.Erase_Hosting_Unit(hostUnit.Clone()); } catch (KeyNotFoundException ex) { throw new KeyNotFoundException(ex.Message); } return; }
/// <summary> /// adds a new hosting unit to the data /// </summary> /// <param name="hostingUnit"></param> void IDal.AddHostingUnit(HostingUnit hostingUnit) { var v = from item in DataSource.HostingUnitsList where item.HostingUnitKey == hostingUnit.HostingUnitKey select item; if (v.FirstOrDefault() != null) { throw new InvalidOperationException("The Hosting Unit Already Exist"); } hostingUnit.HostingUnitKey = Configuration.HostUnitKey++; foreach (var item in DataSource.HostsList) //adds 1 to num of hosting units of owner in hosts list { if (item.HostKey == hostingUnit.Owner.HostKey) { item.NumOfHostingUnits++; } } foreach (var item in DataSource.HostingUnitsList) { if (item.Owner.HostKey == hostingUnit.Owner.HostKey) { item.Owner.NumOfHostingUnits++; } } //hostingUnit.Owner.NumOfHostingUnits++; hostingUnit.Diary = new bool[12, 31]; DataSource.HostingUnitsList.Add(hostingUnit.Clone()); }
/// <summary> /// Returns a hosting unit by the Name /// </summary> /// <param name="hostingUnitName">Unit Name</param> /// <returns>HostingUnit</returns> public HostingUnit GetHostingUnitByName(string hostingUnitName) { try { Load(ref hostingUnitsRoot, hostingUnitsPath); } catch (DirectoryNotFoundException r) { throw r; } XElement host1; host1 = (from hos in hostingUnitsRoot.Elements() where hos.Element("hostingUnitName").Value == hostingUnitName select hos).FirstOrDefault(); if (host1 == null) { throw new KeyNotFoundException("Error! Host Unit with specific name not found"); } List <HostingUnit> HostUnits = LoadFromXML <List <HostingUnit> >(hostingUnitsPath); HostingUnit host = new HostingUnit(); foreach (var item in HostUnits) { if (item.hostingUnitName == hostingUnitName) { host = item.Clone(); break; } } return(host.Clone()); }
/// <summary> /// Returns a hosting unit by the ID /// </summary> /// <param name="hostingUnitkey">ID's unit</param> /// <returns>HostingUnit</returns> public HostingUnit GetHostingUnit(int hostingUnitkey) { try { Load(ref HostingUnitsRoot, HostingUnitsPath); } catch (DirectoryNotFoundException r) { throw r; } XElement host1; host1 = (from hos in HostingUnitsRoot.Elements() where int.Parse(hos.Element("HostingUnitKey").Value) == hostingUnitkey select hos).FirstOrDefault(); if (host1 == null) { throw new KeyNotFoundException("שגיאה! לא קיימת במערכת יחידה עם מפתח זה"); } List <HostingUnit> hostunits = LoadFromXML <List <HostingUnit> >(HostingUnitsPath); HostingUnit host = new HostingUnit(); foreach (var item in hostunits) { if (item.HostingUnitKey == hostingUnitkey) { host = item.Clone(); break; } } return(host.Clone()); }
public void updateHostingUnit(HostingUnit hostingUnit) { int index = hostingUnitList.FindIndex(Item => Item.HostingUnitKey == hostingUnit.HostingUnitKey); hostingUnitList[index] = hostingUnit.Clone(); tool.SaveToXML <List <HostingUnit> >(hostingUnitList, hostingUnitsPath); }
public void addHostingUnit(HostingUnit hu) { List <HostingUnit> lst = loadListFromXML <HostingUnit>(UnitsRootPath); if (lst.Exists(item => item.HostingUnitKey == hu.HostingUnitKey) == true) { throw new ArgumentException("This hosting unit already exists"); } else { bool [,] Diary = new bool[13, 31]; for (int i = 0; i < 13; i++) { for (int j = 0; j < 31; j++) { Diary[i, j] = false; } } hu.Diary = Diary; lst.Add(hu.Clone()); int config = Convert.ToInt32(ConfigRoot.Element("hostingUnitKey").Value); config++; ConfigRoot.Element("hostingUnitKey").Value = Convert.ToString(config); ConfigRoot.Save(ConfigRootPath); saveListToXML <HostingUnit>(lst, UnitsRootPath); } }
/// <summary> /// Returns a hosting unit by the Name /// </summary> /// <param name="hostingUnitName">Unit Name</param> /// <returns>HostingUnit</returns> public HostingUnit GetHostingUnitByName(string hostingUnitName) { try { Load(ref HostingUnitsRoot, HostingUnitsPath); } catch (DirectoryNotFoundException r) { throw r; } XElement host1; host1 = (from hos in HostingUnitsRoot.Elements() where hos.Element("HostingUnitName").Value == hostingUnitName select hos).FirstOrDefault(); if (host1 == null) { throw new KeyNotFoundException("שגיאה! לא קיימת במערכת יחידה עם שם זה"); } List <HostingUnit> HostUnits = LoadFromXML <List <HostingUnit> >(HostingUnitsPath); HostingUnit host = new HostingUnit(); foreach (var item in HostUnits) { if (item.HostingUnitName == hostingUnitName) { host = item.Clone(); break; } } return(host.Clone()); }
//----------------------------------------------------------------- public void updateHostingUnit(HostingUnit hu) { if (hu.Owner.CollectionClearance == false) { int ID = hu.Owner.ID; foreach (var item in dal.getOrders()) { int x = item.HostingUnitKey; int y = dal.getHostingUnits().FindIndex(otherItem => otherItem.HostingUnitKey == x); if (dal.getHostingUnits()[x].Owner.ID == ID) { if (item.Status == RequestStatus.Open) { throw new ArgumentException("there are still open orders with this host"); } } } } try { dal.updateHostingUnit(hu.Clone()); } catch (Exception s) { throw s; } }
public void RemoveCollectionClearance(int hotingUnitNumber) { HostingUnit old = (from unit in myDal.GetAllHostingUnits() where unit.HostingUnitKey == hotingUnitNumber select unit).FirstOrDefault(); if (old == null) { throw new NotExistingKeyException(); } foreach (Order order in myDal.GetAllOrders()) { if (CheckOrderInOpenStatus(order) && order.HostingUnitKey == hotingUnitNumber) { throw new HostingUnitConnectedToOrderException(); } } old.Owner.CollectionClearance = Y_N.No; try { myDal.UpdateHostingUnit(old.Clone()); } catch (Exception e) { throw e; } }
public void AddHostingUnit(HostingUnit myHostingUnit) { DS.DataSource.HostingUnitList = LoadListFromXML <HostingUnit>(hostingUnitRootPath); if (DS.DataSource.HostingUnitList.Exists(x => x.HostingUnitKey == myHostingUnit.HostingUnitKey)) { throw new ExistValueException("Hosting Unit number exists in the system"); } HostingUnit hostIsExist = DS.DataSource.HostingUnitList.Find(x => x.Owner.MailAddress == myHostingUnit.Owner.MailAddress); if (hostIsExist == default(HostingUnit)) { Configuration.HostID++; myHostingUnit.Owner.HostKey = Configuration.HostID; } else { myHostingUnit.Owner.HostKey = hostIsExist.Owner.HostKey; } Configuration.HostingUnitID++; myHostingUnit.HostingUnitKey = Configuration.HostingUnitID; DS.DataSource.HostingUnitList.Add(myHostingUnit.Clone()); SaveListToXML(DS.DataSource.HostingUnitList, hostingUnitRootPath); UpdateConfig("HostingUnitID", Configuration.HostingUnitID); UpdateConfig("HostID", Configuration.HostID); }
public long AddUnit(HostingUnit hostingUnit) { HostingUnit hostingUnitCopy = (HostingUnit)hostingUnit.Clone(); hostingUnitCopy.HostingUnitKey = Configuration.HostUnitKey++; DataSource.HostingUnitsCollection.Add(hostingUnitCopy); return(hostingUnit.HostingUnitKey); }
/// <summary> /// Add a new host unit to Data Base /// </summary> /// <param name="addHostingUnit">host unit to be added</param> public void AddAHostingUnit(HostingUnit addHostingUnit) { //check if the price for the unit is not less than 0 if (addHostingUnit.UnitPrice < 0) { throw new Exception("Price must be greater than or equal to zero"); } addHostingUnit.Diary = new bool[12, 31]; addHostingUnit.DiaryFlatten = new bool[12 * 31]; addHostingUnit.SumOfferOrders = 0; addHostingUnit.SumCompletedOrders = 0; addHostingUnit.HostingUnitKey = IDAL.Configuration.HostingUnitKey++; _idalImp.AddAHostingUnit(addHostingUnit.Clone()); _idalImp.AddAHostingUnit(addHostingUnit.Clone()); }
public void UpdateHostingUnit(HostingUnit hostingUnit) { int count = DataSource.hostingUnits.RemoveAll(x => x.Key == hostingUnit.Key); if (count == 0) { throw new MissingIdException("HostingUnit", hostingUnit.Key); } DataSource.hostingUnits.Add(hostingUnit.Clone()); }
public HostingUnit GetHostingUnit(int HKey) { HostingUnit hosting = XmlDataSource.LoadFromXML <List <HostingUnit> >(HostingUnitPath).Where(item => item.HostingUnitKey == HKey).FirstOrDefault(); if (hosting == null) { throw new Exception("Unit with Key [" + HKey + "] does not exist"); } return(hosting.Clone()); }
public void UpdateHostingUnit(HostingUnit unit) { int count = DataSource.hostingUnits.RemoveAll(x => x.Key == unit.Key); if (count == 0) { throw new MissingMemberException("Unit Key", Convert.ToString(unit.Key)); } DataSource.hostingUnits.Add(unit.Clone()); }
/// <summary> /// updates a hosting unit in the data /// </summary> /// <param name="hostingUnit"></param> void IDal.UpdateHostingUnit(HostingUnit hostingUnit) { int Index = DataSource.HostingUnitsList.FindIndex(t => t.HostingUnitKey == hostingUnit.HostingUnitKey); if (Index == -1) { throw new KeyNotFoundException("The Hosting Unit Not Exist"); } DataSource.HostingUnitsList[Index] = hostingUnit.Clone(); }
/// <summary> /// This function updates a hosting unit /// </summary> /// <exception cref="KeyNotFoundException">Thrown when hosting unit with <paramref name="key"/> is not found</exception> /// <param name="hu">Hosting unit to update to</param> /// <param name="key">Key of hosting unit to update</param> public void UpdateHostingUnit(HostingUnit hu, int key) { int index = DataSource.hostingUnitsList.FindIndex(new Predicate <HostingUnit>(x => x.HostingUnitKey == key)); if (-1 == index) { throw new KeyNotFoundException("No hosting unit with key specified found"); } DataSource.hostingUnitsList[index] = hu.Clone(); }
//----------------------------------------------------------------- public void addHostingUnit(HostingUnit hu) { try { dal.addHostingUnit(hu.Clone()); } catch (Exception s) { throw s; } }
public void AddHostingUnit(HostingUnit newHostingUnit) { if (GetHostingUnitsList().Any(x => x.HostingUnitKey == newHostingUnit.HostingUnitKey)) { throw new TzimerException($"Hosting Unit with the ID: {newHostingUnit.HostingUnitKey} - already exists!", "dal"); } newHostingUnit.HostingUnitKey = Configuration.HostingUnitId++; newHostingUnit.Diary = Utils.CreateMatrix(); DataSource.unitList.Add((HostingUnit)newHostingUnit.Clone()); }
public long AddUnit(HostingUnit hostingUnit) { HostingUnit hostingUnitCopy = (HostingUnit)hostingUnit.Clone(); hostingUnitCopy.HostingUnitKey = XC.GetConfiguration <long>("HostUnitKey"); DataSource.HostingUnitsCollection.Add(hostingUnitCopy); XmlDataSource.SaveToXML <List <HostingUnit> >(DataSource.HostingUnitsCollection, HostingUnitPath); XC.UpdateConfiguration <long>("HostUnitKey", (hostingUnitCopy.HostingUnitKey + 1)); return(hostingUnitCopy.HostingUnitKey); //XH.AddUnit(hostingUnit); }
public void UpdateHostingUnit(HostingUnit myHostingUnit) { int isExist = DS.DataSource.HostingUnitList.FindIndex(x => x.HostingUnitKey == myHostingUnit.HostingUnitKey); if (isExist == -1) { throw new KeyNotFoundException("Hosting unit does not exist in the system"); } DS.DataSource.HostingUnitList.RemoveAt(isExist); DS.DataSource.HostingUnitList.Add(myHostingUnit.Clone()); }
public void DeleteHostingUnit(HostingUnit hostingUnit) // { int count = DataSource.hostingUnits.RemoveAll(x => hostingUnit.Key == x.Key); if (count == 0) { throw new MissingIdException("hostingUnit", hostingUnit.Key); } hostingUnit.Status = Status.INACTIVE; DataSource.hostingUnits.Add(hostingUnit.Clone()); }
/// <summary> /// Updates a hosting unit /// </summary> /// <param name="hostUnit"></param> public void Update_Hosting_Unit(HostingUnit hostUnit) { try { Dal.Update_Hosting_Unit(hostUnit.Clone()); } catch (KeyNotFoundException ex) { throw new KeyNotFoundException(ex.Message); } }
public void AddHostingUnit(HostingUnit hostingUnit) { hostingUnit.HostingUnitKey = Configuration.HostingUnitKey++; if (DataSource.hostingUnits.Any(item => hostingUnit.HostingUnitKey == item.HostingUnitKey)) { throw new DuplicateWaitObjectException("This key already exists, DAL error"); } DataSource.hostingUnits.Add(hostingUnit.Clone()); DataSource_XML.saveConf(); DataSource_XML.SaveToXML(DataSource.hostingUnits, hostingUnitPath); }
public void addHostingUnit(HostingUnit hstUnit) { if (!CheckHostingUnit(hstUnit.HostingUnitKey)) { dataSource.hostingUnits.Add(hstUnit.Clone()); } else { throw new Exception("a"); //TODO // DuplicateIdException() } }
public void UpdateHostUnit(HostingUnit hostingUnit) { int index = DataSource.getHostingUnits().FindIndex(t => t.HostingUnitKey == hostingUnit.HostingUnitKey);//finds ondex of unit with key // hostingUnit.HostingUnitKey = GetHostingUnit(hostingUnit.HostingUnitName).HostingUnitKey; if (index == -1)//meaning name not found { throw new DuplicateWaitObjectException("No Hosting Unit with this name Exists!"); } DataSource.getHostingUnits()[index] = hostingUnit.Clone();//update the hosting unit }
public void UpdateHostingUnit(HostingUnit unit) { unitsHandler.load(); int count = hostingUnits.RemoveAll(x => x.Key == unit.Key); if (count == 0) { throw new MissingMemberException("Unit Key", Convert.ToString(unit.Key)); } hostingUnits.Add(unit.Clone()); unitsHandler.Save(); }
//----------------------------------------------------------------- public void addHostingUnit(HostingUnit hu) { if (DataSource.hostingUnitList.Exists(item => item.HostingUnitKey == hu.HostingUnitKey) == true) { throw new ArgumentException("This hosting unit already exists"); } else { DataSource.hostingUnitList.Add(hu.Clone()); Configuration.hostingUnitKey++; } }
public HostingUnit GetHostingUnit(int key) { HostingUnit findHostingUnit = (from unit in DataSource.hostingUnitsList where unit.Key == key select unit).FirstOrDefault(); if (findHostingUnit != null && findHostingUnit.Status == ActivityStatus.ACTIVE) { return(findHostingUnit.Clone()); } throw new Exception("This Hosting unit us not exist");///need to check if hosting unit status is active????? }
public void UpdateHostingUnit(HostingUnit hostingUnit) { List <HostingUnit> hostingUnitList = LoadFromXML <List <HostingUnit> >(hostingUnitPath); int numberDeleted = hostingUnitList.RemoveAll(unit => unit.HostingUnitKey == hostingUnit.HostingUnitKey); if (numberDeleted == 0)//which means nothing was deleted { throw new NotExistingKeyException(); } hostingUnitList.Add(hostingUnit.Clone()); SaveToXML(hostingUnitList, hostingUnitPath); }