public ItemBriefDetails GetItemBriefDetails(ItemBriefRequestDetails itemBriefRequestDetails)
        {
            ItemBriefDetails itemBriefDetails = new Data.DataTypes.ItemBriefDetails();

            using (StageBitzDB dataContext = new StageBitzDB())
            {
                try
                {
                    ItemBriefBL itemBriefBL = new ItemBriefBL(dataContext);
                    ItemTypesBL itemTypesBL = new ItemTypesBL(dataContext);

                    Data.ItemBrief itemBrief = itemBriefBL.GetItemBrief(itemBriefRequestDetails.ItemBriefId);

                    int projectId = 0;
                    if (itemBrief != null)
                    {
                        projectId = itemBrief.ProjectId;
                    }

                    itemBriefDetails.CountryId = itemBriefBL.GetCountryIdByItemBriefId(itemBrief.ItemBriefId);

                    itemBriefDetails.ItemBriefInfo       = itemBriefBL.GetItemBriefInfoByItemBrief(itemBrief);
                    itemBriefDetails.IsReadOnly          = Support.IsReadOnlyRightsForProject(projectId, itemBriefRequestDetails.UserId);
                    itemBriefDetails.CanSeeBudgetSummary = Support.CanSeeBudgetSummary(itemBriefRequestDetails.UserId, projectId);
                    int itemTypeId = itemBriefRequestDetails.ItemTypeId.HasValue ?
                                     itemBriefRequestDetails.ItemTypeId.Value : itemBriefBL.GetItemBriefType(itemBriefRequestDetails.ItemBriefId).ItemTypeId;
                    itemBriefDetails.DisplayMarkUp   = itemTypesBL.GetItemTypeHTML(itemTypeId);
                    itemBriefDetails.ItemBriefValues = itemTypesBL.GetItemBriefFieldValues(itemBriefRequestDetails.ItemBriefId).Select(ibfv =>
                                                                                                                                       new ValuesInfo
                    {
                        Id            = ibfv.ItemBriefValueId,
                        FieldId       = ibfv.FieldId,
                        FieldOptionId = ibfv.FieldOptionId,
                        Value         = ibfv.Value
                    }).ToList();

                    int itemId = 0;
                    int userId = 0;

                    ItemBooking itemBooking = itemBriefBL.GetInUseItemBooking(itemBriefRequestDetails.ItemBriefId);
                    if (itemBooking != null)
                    {
                        itemId = itemBooking.ItemId;
                    }

                    userId = itemBriefRequestDetails.UserId;
                    ItemDetails itemDetails = itemTypesBL.GetItemDetails(itemId, itemBriefRequestDetails.ItemBriefId, userId, null, null, null);
                    if (itemDetails != null)
                    {
                        itemBriefDetails.ItemDetails = itemDetails;
                    }
                }
                catch (Exception ex)
                {
                    AgentErrorLog.HandleException(ex);
                }
                return(itemBriefDetails);
            }
        }
Exemple #2
0
        /// <summary>
        /// Initializes the ids.
        /// </summary>
        /// <param name="itemId">The item identifier.</param>
        /// <param name="itemBriefId">The item brief identifier.</param>
        /// <param name="isItemCreated">if set to <c>true</c> [is item created].</param>
        public void InitializeIds(ref int itemId, ref int itemBriefId, ref bool isItemCreated)
        {
            InventoryBL inventoryBL = new InventoryBL(DataContext);
            ItemBriefBL itemBriefBL = new ItemBriefBL(DataContext);

            if (itemId > 0)
            {
                StageBitz.Data.Item item = inventoryBL.GetItem(itemId);

                if (item != null)
                {
                    isItemCreated = true;
                }
            }
            else if (itemBriefId > 0)
            {
                StageBitz.Data.ItemBrief itemBrief = itemBriefBL.GetItemBrief(itemBriefId);

                if (itemBrief != null)
                {
                    ItemBooking itemBooking = itemBriefBL.GetInUseItemBooking(itemBriefId);

                    Data.Item item = null;
                    if (itemBooking != null)
                    {
                        item = itemBooking.Item;
                    }

                    if (item != null)
                    {
                        itemId        = item.ItemId;
                        isItemCreated = true;
                    }
                    else
                    {
                        isItemCreated = false;
                    }
                }
            }
        }
Exemple #3
0
        /// <summary>
        /// Saves the item details.
        /// </summary>
        /// <param name="itemDetails">The item details.</param>
        /// <param name="skipConcurrencyCheck">if set to <c>true</c> [skip concurrency check].</param>
        /// <param name="shouldCommit">if set to <c>true</c> [should commit].</param>
        /// <returns></returns>
        public ItemResultObject SaveItemDetails(ItemDetails itemDetails, bool skipConcurrencyCheck = false, bool shouldCommit = false)
        {
            ItemResultObject itemResultObject = new ItemResultObject();
            ItemBriefBL      itemBriefBL      = new ItemBriefBL(DataContext);
            InventoryBL      inventoryBL      = new InventoryBL(DataContext);
            ProjectBL        projectBL        = new ProjectBL(DataContext);
            LocationBL       locationBL       = new LocationBL(DataContext);
            CompanyBL        companyBL        = new CompanyBL(DataContext);

            int itemId    = itemDetails.ItemId;
            int companyId = 0;
            int projectId = 0;

            Data.ItemBrief itemBrief = itemBriefBL.GetItemBrief(itemDetails.ItemBriefId);
            Data.Item      item      = inventoryBL.GetItem(itemId);

            if (itemDetails.ItemId > 0)
            {
                companyId = item.CompanyId.Value;
            }
            else if (itemBrief != null && item == null)
            {
                companyId = itemBrief.Project.CompanyId;
                projectId = itemBrief.ProjectId;

                item           = new Item();
                item.CompanyId = companyId;
            }

            bool   isInventoryPage = itemDetails.RelatedTable == "Company";
            string relatedTable    = "Company";
            int    relatedId       = companyId;

            if (itemDetails.RelatedTable == "Project" && projectId > 0)
            {
                relatedTable = itemDetails.RelatedTable;
                relatedId    = projectId;
            }

            if (!projectBL.ShouldStopProcessing(relatedTable, relatedId, itemDetails.UserId))
            {
                ErrorCodes errorCode;
                if (itemDetails.ItemBriefId > 0 && !inventoryBL.CanEditIteminItemBrief(itemDetails.ItemBriefId, itemDetails.ItemId))
                {
                    itemResultObject.Status    = "CONCURRENCY";
                    itemResultObject.ErrorCode = (int)ErrorCodes.NoEditPermissionForItemInItemBrief;
                    itemResultObject.Message   = "No Write Permission";

                    return(itemResultObject);
                }
                else if (relatedTable == "Company" && itemId > 0 && inventoryBL.CheckPermissionsForItemDetailsPage(itemDetails.UserId, itemId, companyId, out errorCode, false) == null)
                {
                    itemResultObject.Status    = "CONCURRENCY";
                    itemResultObject.ErrorCode = (int)errorCode;
                    itemResultObject.Message   = "No Write Permission";

                    return(itemResultObject);
                }
                else if (!skipConcurrencyCheck && itemId > 0 && itemDetails.LastUpdatedDate != item.LastUpdatedDate)
                {
                    itemResultObject.Status  = "NOTOK";
                    itemResultObject.Message = "Can not update";
                    return(itemResultObject);
                }

                item.Name        = itemDetails.Name;
                item.Description = itemDetails.Description;

                if (itemDetails.IsEditableToAdminOnly && item.Quantity != itemDetails.Quantity)//Commit if changes exist
                {
                    bool canSaveQty = true;
                    if (item.Quantity > itemDetails.Quantity)//Only when reduces Units
                    {
                        int maxBookedQty = inventoryBL.GetMaxBookedQuantityForAllDuration(itemDetails.ItemId);

                        if (maxBookedQty > itemDetails.Quantity)
                        {
                            canSaveQty = false;
                        }
                    }

                    if (canSaveQty)
                    {
                        item.Quantity = itemDetails.Quantity;
                    }
                    else
                    {
                        itemResultObject.Status    = "CONCURRENCY";
                        itemResultObject.ErrorCode = (int)ErrorCodes.QuantityUpdateFailed;
                        itemResultObject.Message   = "Can not reduce quantity";
                        return(itemResultObject);
                    }
                }
                item.LastUpdatedByUserId = itemDetails.UserId;
                item.LastUpdatedDate     = Utils.Now;

                if (isInventoryPage)
                {
                    if (companyBL.HasEditPermissionForInventoryStaff(companyId, itemDetails.UserId, itemDetails.LocationId))
                    {
                        item.CreatedFor = itemDetails.CreatedFor;

                        if (itemDetails.LocationId.HasValue)
                        {
                            Data.Location location = locationBL.GetLocation(itemDetails.LocationId.Value);
                            if (location == null)
                            {
                                itemResultObject.Status    = "CONCURRENCY";
                                itemResultObject.ErrorCode = (int)ErrorCodes.InventoryLocationDeleted;
                                itemResultObject.Message   = "Item Location not available";
                                return(itemResultObject);
                            }
                        }

                        item.LocationId = itemDetails.LocationId;
                    }
                    else
                    {
                        itemResultObject.Status    = "CONCURRENCY";
                        itemResultObject.ErrorCode = (int)ErrorCodes.NoEditPermissionForInventory;
                        itemResultObject.Message   = "No Edit Permission For Item In Inventory";
                        return(itemResultObject);
                    }
                }

                if (itemDetails.ItemTypeId.HasValue)
                {
                    item.ItemTypeId = itemDetails.ItemTypeId;
                }

                //Update ItemBooking
                if (itemBrief != null)
                {
                    ItemBooking itemBooking = inventoryBL.GetItemBookingByItemID(itemId, itemBrief.ItemBriefId, "ItemBrief");
                    itemBooking.Quantity       = itemDetails.Quantity.Value;
                    itemBooking.LastUpdateDate = Utils.Now;
                    itemBooking.LastUpdatedBy  = itemDetails.UserId;
                }

                if (itemDetails.ItemValues != null)
                {
                    foreach (ValuesInfo iValue in itemDetails.ItemValues)
                    {
                        if (iValue.Id == 0)
                        {
                            //It is an Insert
                            ItemValue iValueNew = new ItemValue();
                            iValueNew.ItemId        = item.ItemId;
                            iValueNew.FieldId       = iValue.FieldId;
                            iValueNew.Value         = iValue.Value;
                            iValueNew.FieldOptionId = iValue.FieldOptionId;
                            DataContext.ItemValues.AddObject(iValueNew);
                        }
                        else
                        {
                            //Update
                            ItemValue itemValue = GetItemFieldValueById(iValue.Id);
                            if (itemValue != null)
                            {
                                if (iValue.Value == string.Empty && iValue.FieldOptionId == null)
                                {
                                    DataContext.ItemValues.DeleteObject(itemValue);
                                }
                                else
                                {
                                    itemValue.FieldOptionId = iValue.FieldOptionId;
                                    itemValue.Value         = iValue.Value;
                                }
                            }
                        }
                    }
                }

                if (shouldCommit)
                {
                    DataContext.SaveChanges();
                }

                itemResultObject.Status = "OK";
                return(itemResultObject);
            }
            else
            {
                itemResultObject.Status = "STOPPROCESS";
                return(itemResultObject);
            }
        }
Exemple #4
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);
        }