コード例 #1
0
        /// <summary>
        /// Gets the item details.
        /// </summary>
        /// <param name="itemId">The item identifier.</param>
        /// <param name="itemBriefId">The item brief identifier.</param>
        /// <param name="userId">The user identifier.</param>
        /// <param name="itemTypeIdToBeLoad">The item type identifier to be load.</param>
        /// <param name="fromDate">From date.</param>
        /// <param name="toDate">To date.</param>
        /// <returns></returns>
        public ItemDetails GetItemDetails(int itemId, int itemBriefId, int userId, int?itemTypeIdToBeLoad, DateTime?fromDate = null, DateTime?toDate = null)
        {
            bool isItemCreated = false;
            bool isReadOnly    = false;
            int  itemTypeId    = 0;

            InventoryBL inventoryBL = new InventoryBL(DataContext);
            ItemBriefBL itemBriefBL = new ItemBriefBL(DataContext);

            ItemDetails itemDetails = new ItemDetails();

            InitializeIds(ref itemId, ref itemBriefId, ref isItemCreated);

            if (itemId > 0)
            {
                StageBitz.Data.Item item = inventoryBL.GetItem(itemId);
                if (item != null)
                {
                    ItemBooking itemBooking = null;
                    itemDetails.IsEditableToAdminOnly = true;

                    if (itemBriefId > 0)
                    {
                        ProjectBL projectBL = new ProjectBL(DataContext);
                        itemBooking = itemBriefBL.GetInUseItemBooking(itemBriefId);
                        itemDetails.CanEditInItemBrief    = inventoryBL.CanEditIteminItemBrief(itemBriefId, itemId);
                        itemDetails.IsEditableToAdminOnly = inventoryBL.IsItemGeneretedFromGivenItemBrief(itemId, itemBriefId) && !projectBL.IsReadOnlyRightsForProject(itemBriefBL.GetItemBrief(itemBriefId).ProjectId, userId, true);
                    }
                    else
                    {
                        itemDetails.MinQuantity = inventoryBL.GetMaxBookedQuantityForAllDuration(item.ItemId);

                        ItemStatusInformationForUser itemStatusInformationForUser = inventoryBL.GetItemStatusInformationForUser(item, item.CompanyId.Value, userId);
                        isReadOnly = itemStatusInformationForUser.IsReadOnly;
                        itemDetails.IsEditableToAdminOnly = itemStatusInformationForUser.CanEditQuantity;
                    }

                    itemDetails.Name        = item.Name;
                    itemDetails.Description = item.Description;
                    itemDetails.LocationId  = item.LocationId;
                    itemDetails.Quantity    = itemBooking != null ? itemBooking.Quantity : item.Quantity.HasValue ? item.Quantity.Value : item.Quantity;

                    User bookingManager = inventoryBL.GetContactBookingManager(item.CompanyId.Value, item.LocationId);
                    if (bookingManager != null)
                    {
                        itemDetails.BookingManagerName  = Utils.GetFullName(bookingManager);
                        itemDetails.BookingManagerEmail = bookingManager.Email1;
                    }

                    if (fromDate.HasValue && toDate.HasValue)
                    {
                        itemDetails.AvailableQty = DataContext.GetAvailableItemQuantity(itemId, fromDate.Value, toDate.Value, 0).FirstOrDefault().Value;
                    }
                    itemDetails.CreatedFor      = item.CreatedFor;
                    itemDetails.ItemBriefId     = itemBriefId;
                    itemDetails.LastUpdatedDate = item.LastUpdatedDate;
                    itemTypeId = itemTypeIdToBeLoad.HasValue ? itemTypeIdToBeLoad.Value : item.ItemTypeId.Value;

                    itemDetails.LastUpdatedDate = item.LastUpdatedDate;

                    itemDetails.ItemStatus = itemBooking != null?inventoryBL.GetItemBookingStatus(itemBooking.ItemBookingId).Description : string.Empty;

                    itemDetails.ItemId     = itemId;
                    itemDetails.ItemValues = GetItemFieldValues(itemId).Select(iv =>
                                                                               new ValuesInfo
                    {
                        Id            = iv.ItemValueId,
                        FieldId       = iv.FieldId,
                        FieldOptionId = iv.FieldOptionId,
                        Value         = iv.Value
                    }).ToList();

                    itemDetails.CountryId  = inventoryBL.GetCountryIdByItemId(item.ItemId);
                    itemDetails.ItemTypeId = item.ItemTypeId;
                    itemDetails.Status     = "OK";
                }
            }
            else if (itemBriefId > 0)
            {
                Data.ItemVersionHistory itemVersionHistory = inventoryBL.GetItemVersionHistoryByItemBriefId(itemBriefId);
                itemDetails.ItemBriefId = itemBriefId;
                if (itemVersionHistory != null)
                {
                    itemId                            = itemVersionHistory.ItemId;
                    itemDetails.Name                  = itemVersionHistory.Name;
                    itemDetails.Description           = itemVersionHistory.Description;
                    itemDetails.LocationId            = null; //itemVersionHistory.Location;
                    itemDetails.Quantity              = itemVersionHistory.Quantity.HasValue ? itemVersionHistory.Quantity.Value : itemDetails.Quantity;
                    itemDetails.IsEditableToAdminOnly = false;
                    itemDetails.ItemBriefId           = itemVersionHistory.ItemBriefId;
                    itemDetails.ItemValues            = GetItemVersionHistoryValues(itemVersionHistory.ItemVersionHistoryId).Select(ivhv =>
                                                                                                                                    new ValuesInfo
                    {
                        Id            = ivhv.ItemVersionHistoryId,
                        FieldId       = ivhv.FieldId,
                        FieldOptionId = ivhv.FieldOptionId,
                        Value         = ivhv.Value
                    }).ToList();
                    itemTypeId             = itemTypeIdToBeLoad.HasValue ? itemTypeIdToBeLoad.Value : itemVersionHistory.ItemTypeId.Value;
                    itemDetails.CountryId  = inventoryBL.GetCountryIdByItemId(itemVersionHistory.ItemId);
                    itemDetails.ItemTypeId = itemVersionHistory.ItemTypeId;
                    itemDetails.Status     = "OK";
                }
                else
                {
                    StageBitz.Data.ItemBrief itemBrief = itemBriefBL.GetItemBrief(itemBriefId);
                    if (itemBrief != null)
                    {
                        itemDetails.Name                  = itemBrief.Name;
                        itemDetails.Description           = itemBrief.Description;
                        itemDetails.LocationId            = null;
                        itemDetails.IsEditableToAdminOnly = true;
                        itemDetails.ItemBriefId           = itemBriefId;
                        itemDetails.Quantity              = itemBrief.Quantity.HasValue ? itemBrief.Quantity.Value : itemBrief.Quantity;
                        itemDetails.ItemBriefId           = itemBrief.ItemBriefId;
                        itemDetails.ItemValues            = GetItemBriefFieldValues(itemBriefId).Select(ibfv =>
                                                                                                        new ValuesInfo
                        {
                            Id            = 0,
                            FieldId       = ibfv.FieldId,
                            FieldOptionId = ibfv.FieldOptionId,
                            Value         = ibfv.Value
                        }).ToList();

                        itemTypeId                     = itemTypeIdToBeLoad.HasValue ? itemTypeIdToBeLoad.Value : itemBriefBL.GetItemBriefType(itemBrief.ItemBriefId).ItemTypeId;
                        itemDetails.CountryId          = itemBriefBL.GetCountryIdByItemBriefId(itemBrief.ItemBriefId);
                        itemDetails.Status             = "OK";
                        itemDetails.CanEditInItemBrief = true;
                        itemDetails.ItemTypeId         = itemBrief.ItemBriefTypes.FirstOrDefault().ItemTypeId;
                    }
                }
            }

            itemDetails.IsReadOnly    = isReadOnly;
            itemDetails.DisplayMarkUp = GetItemTypeHTML(itemTypeId);

            Data.ItemType itemType = Utils.GetItemTypeById(itemDetails.ItemTypeId.Value);
            itemDetails.ItemTypeName = itemType != null ? itemType.Name : string.Empty;

            return(itemDetails);
        }