예제 #1
0
        public static List<SimplUser> ToSimplUserList(List<Entity> entityList, bool includeId = false)
        {
            var returnList = new List<SimplUser>();

            // if uniqueIds must be included
            if (includeId)
            {
                var id = string.Empty;
                using (var db = DBContextFactory.CreateContext())
                {
                    if (entityList != null)
                    {
                        foreach (var entity in entityList)
                        {
                            if (db.UniqueIds.Any(u => u.EntityId == entity.EntityId))
                            {
                                var uniqueId = db.UniqueIds.FirstOrDefault(i => i.EntityId == entity.EntityId);
                                if (uniqueId != null)
                                {
                                    id = uniqueId.UniqueIdValue;
                                }
                            }
                            var user = new SimplUser(entity.EntityId, entity.EntityName1, entity.EntityName2, id);
                            returnList.Add(user);
                        }
                    }
                }
            }
            else
            { // if no ids need to be included
                returnList.AddRange(entityList.Select(entity => new SimplUser(entity.EntityId, entity.EntityName1, entity.EntityName2)));
            }
            return returnList;
        }
예제 #2
0
        private string FormatOrder(Order order)
        {
            try
            {
                //Todo: This entire method should be rewritten or the functionality should be moved to a partial. Also, a StringBuilder should be used. Also, the context should only be open long enough to get the data, and the text formatting should occur after it's closed.
                var output = "";
                const string cellString = "<td style=\"border: 1px solid black;\">";
                const int tableColCount = 4;
                using (var db = DBContextFactory.CreateContext())
                {
                    var master = db.MasterOrders.First(m => m.MasterOrderId == order.MasterOrderId);

                    var creator = new SimplUser(db.Entities.First(e => e.EntityId == master.CreatingEntityId));
                    var receiver = new SimplUser(db.Entities.First(e => e.EntityId == master.ReceivingEntityId));
                        //TODO: make this compatible with deers and cows and dropship orders

                    SimplUser fulfiller = null;
                    var fulfilledBy = db.Entities.FirstOrDefault(u => u.EntityId == order.FilledByEntityId);
                    if (fulfilledBy != null)
                        fulfiller = new SimplUser(db.Entities.FirstOrDefault(u => u.EntityId == order.FilledByEntityId));

                    var loc = db.Locations.First(l => l.LocId == master.Entity1.Location.LocId);

                    // get the order items from the database and parse by IsSerialized field
                    var orderItems = db.OrderLineItems.Where(o => o.OrderId == order.OrderId).ToList();
                    var nsOrderItems =
                        orderItems.Where(q => q.EquipmentType.EquipmentCategory.IsSerialized == false).ToList();
                    var sOrderItems = orderItems.Where(q => q.EquipmentType.EquipmentCategory.IsSerialized).ToList();
                    var shippedSerials =
                        db.ShippedSerials.Where(
                            s => orderItems.Select(o => o.OrderLineItemId).Contains((int) s.OrderLineItemId));

                    output += "<br /><br /><b>Order Details</b><br />";
                    output += "Order id: " + order.MasterOrderId + "<br />";
                    output += "Created by: " + creator.NameAndId + "<br />";
                    output += "Received by: " + receiver.NameAndId + "<br />";
                    if (fulfiller != null)
                        output += "Fulfilled by: " + fulfiller.NameAndId + "<br /> at " +
                                  db.Orders.First(o => o.OrderId == order.OrderId).FilledDateTime;
                    else
                        output += "Fulfilled by: Not Yet Fulfilled<br />";
                    output += "Order placed at: " + master.CreateDateTime + "<br />";
                    output += "Receiving location: " + loc.LocName + ", " + loc.TriadLocId + "<br />";

                    output += "<br /><b>Item Details</b><br />";

                    if (nsOrderItems.Any())
                    {
                        output +=
                            "<table width=\"400px\" style=\"cell-padding:10px; border-width:thin; border-style:solid;\"><tr><td colspan=\"" +
                            tableColCount + "\" style=\"border: 1px solid black;\">Non-serialized:</td></tr>";
                        output += "<tr>" + cellString + "Quantity</td>" + cellString + "Item Number</td>" + cellString +
                                  "Equipment Category</td>" + cellString + "Name/Description</td></tr>";
                        foreach (var item in nsOrderItems)
                        {
                            output += "<tr>" +
                                      cellString + item.Quantity + "</td>" +
                                      cellString + item.EquipmentType.ItemNumber + "</td>" +
                                      cellString + item.EquipmentType.EquipmentCategory.EquipmentCategoryName +
                                      "</td>" +
                                      cellString + item.EquipmentType.EquipName + "</td>" +
                                      "</tr>";
                        }
                    }

                    if (sOrderItems.Any())
                    {
                        output += "<tr><td colspan=\"" + tableColCount + "\"></td></tr>" +
                                  "<tr><td colspan=\"" + tableColCount + "\">Serialized:";
                        if (SerializeItems)
                        {
                            foreach (var serial in shippedSerials)
                            {
                                var myLineItem = orderItems.First(o => o.OrderLineItemId == serial.OrderLineItemId);
                                output += "<tr>" +
                                          "<td>" + serial.SerialNumber + "</td>" +
                                          "<td>" + myLineItem.EquipmentType.EquipmentCategory.EquipmentCategoryName +
                                          "</td>" +
                                          "<td>" + myLineItem.EquipmentType.EquipName + "</td>" +
                                          "</tr>";
                            }
                        }
                        else if (nsOrderItems.Any())
                        {
                            foreach (var item in nsOrderItems)
                            {
                                output += "<tr>" +
                                          "<td>" + item.Quantity + "</td>" +
                                          "<td>" + item.EquipmentType.ItemNumber + "</td>" +
                                          "<td>" + item.EquipmentType.EquipmentCategory.EquipmentCategoryName + "</td>" +
                                          "<td>" + item.EquipmentType.EquipName + "</td>" +
                                          "</tr>";
                            }
                        }

                        output += "</table>";
                    }

                    var comment = db.Comments.FirstOrDefault(c => c.CommentOrderId == order.OrderId);

                    if (comment != null)
                    {
                        output += "<br /><b>Item Details</b><br />";
                        output += "<br />" + comment.CommentText;
                    }
                }
                return output;
            }
            catch
            {
                return string.Empty;
            }
        }