/// <summary> /// Constrains a list of items to certain quantity limits as imposed by the EquipmentTypes table in the SIMPL database /// </summary> public static string EnforceQuantityLimits(List<OrderLineItem> list, SIMPLDbEnums.OrderTypeEnum orderType) { var errorMsg = ""; //This message will be shown if quantities exceed max allowed for (var i = list.Count - 1; i >= 0; i--) { int? maxAllowed; EquipmentType equipType; switch (orderType) { case SIMPLDbEnums.OrderTypeEnum.Drop: equipType = DBCache.EquipmentTypes.FirstOrDefault(e => e.EquipmentTypeId == list[i].EquipTypeId); maxAllowed = equipType != null ? equipType.MaxDropshipQuantity : 0; break; case SIMPLDbEnums.OrderTypeEnum.Field: equipType = DBCache.EquipmentTypes.FirstOrDefault(e => e.EquipmentTypeId == list[i].EquipTypeId); maxAllowed = equipType != null ? equipType.MaxFieldOrderQuantity : 0; break; default: throw new Exception("No order type selected, unable to enforce quantity limitations."); } if (!(list[i].Quantity > maxAllowed)) continue; errorMsg += "\nMax quantity reached for " + DBCache.EquipmentTypes.First(e => e.EquipmentTypeId == list[i].EquipTypeId).EquipName; if (maxAllowed != null && maxAllowed != 0) { list[i].Quantity = (ushort)maxAllowed; } else { list.Remove(list[i]); } } return errorMsg; }
public static void LogSubscriberAction(this Subscriber subscriber, SIMPLDbEnums.SubActionTypeEnum actionType, User user, bool success) { var subAction = new TempModel.SubAction { ActionDateTime = DateTime.Now, ActionTypeId = (int) actionType, ActionDescription = actionType.GetStringValue(), Success = success }; try { using (var db = DBContextFactory.CreateContext()) { subAction.EntityId = db.UniqueIds.First(u => u.UniqueIdValue == user.Name).EntityId; db.SubActions.AddObject(subAction); db.SaveChanges(); } } catch (SqlException ex) { throw new Exception("There was a problem logging the action to the database", ex); } }
/// <summary> /// A method to determine whether a box is in a supported status type in order to perform the /// operation in question (e.g. can't activate a box that is "written off") /// </summary> /// <param name="statusEnum"></param> /// <param name="transEnum"></param> /// <returns></returns> public static Boolean SupportedStatus(SIMPLDbEnums.EquipStatusEnum statusEnum, SIMPLDbEnums.TransactionTypeEnum transEnum) { return true; }