Пример #1
0
        /// <summary>
        /// Set Item Price for Rent
        /// </summary>
        /// <param name="item">Item Rent</param>
        /// <param name="userId">user Id</param>
        /// <returns>Item Rent</returns>
        public ItemRent SetPrice(ItemRent item, Guid userId)
        {
            if (null == item)
            {
                throw new ArgumentNullException("item");
            }

            if (Guid.Empty == userId)
            {
                throw new ArgumentException("userId");
            }

            if (item.Price <= 0)
            {
                throw new ArgumentException("price");
            }

            if (item.PerUnit != RentalUnit.PerDay)
            {
                throw new ArgumentException("unit");
            }

            var itemIdentifier = item.ItemIdentifier.ToNullable();

            if (!itemIdentifier.HasValue)
            {
                throw new ArgumentException("identifier's");
            }

            var sproc = new GoodsSaveItemRent()
            {
                UserIdentifier = userId,
                ItemIdentifier = itemIdentifier,
                PerUnit        = (byte)item.PerUnit,
                Price          = item.Price,
            };

            return(sproc.CallObject <ItemRent>());
        }
Пример #2
0
        /// <summary>
        /// Save Item
        /// </summary>
        /// <param name="item">Item</param>
        /// <returns>Item</returns>
        public Item Save(Item item)
        {
            if (null == item)
            {
                throw new ArgumentNullException("item");
            }

            if (Guid.Empty == item.UserIdentifier)
            {
                throw new ArgumentException("User Identifier");
            }

            var sp = new GoodsSaveItem()
            {
                UserIdentifier    = item.UserIdentifier.ToNullable(),
                Identifier        = item.Identifier.ToNullable(),
                Title             = item.Title.TrimIfNotNull(),
                Description       = item.Description.TrimIfNotNull(),
                Delete            = item.Delete,
                SharePrivacyLevel = item.SharePrivacyLevel == PrivacyLevel.Unknown ? (byte?)null : (byte?)item.SharePrivacyLevel,
                RentPrivacyLevel  = item.RentPrivacyLevel == PrivacyLevel.Unknown ? (byte?)null : (byte?)item.RentPrivacyLevel,
                TradePrivacyLevel = item.TradePrivacyLevel == PrivacyLevel.Unknown ? (byte?)null : (byte?)item.TradePrivacyLevel,
                FreePrivacyLevel  = item.FreePrivacyLevel == PrivacyLevel.Unknown ? (byte?)null : (byte?)item.FreePrivacyLevel,
            };

            var data = sp.Execute().LoadObject <Item>();

            if (null != data)
            {
                if (item.Identifier != data.Identifier && data.IsNew)
                {
                    activityCore.NewItem(data);
                }
                else
                {
                    activityCore.UpdateItem(data);
                }

                if (item.RentPrivacyLevel != PrivacyLevel.Private &&
                    item.RentPrivacyLevel != PrivacyLevel.Unknown &&
                    item.PerUnit == RentalUnit.PerDay &&
                    0 < item.Price)
                {
                    var rent = new ItemRent()
                    {
                        ItemIdentifier = item.Identifier,
                        Price          = item.Price,
                        PerUnit        = item.PerUnit,
                    };

                    var rentCore = new RentCore();
                    var price    = rentCore.SetPrice(rent, item.UserIdentifier);

                    if (null != price)
                    {
                        data.PerUnit = price.PerUnit;
                        data.Price   = price.Price;
                    }
                }
            }

            return(data);
        }