Exemplo n.º 1
0
        /// <summary>
        /// Add a <c>Contract Detail</c> to <c>Contract</c> with required data.
        /// </summary>
        /// <param name="contractId"><c>Contract</c> Id</param>
        /// <param name="customerType"><see cref="CustomerType"/></param>
        /// <param name="customerId">Customer Id</param>
        /// <param name="title">Title (description) of contract line</param>
        /// <param name="startDate">Start date</param>
        /// <param name="endDate">End date</param>
        /// <param name="totalPrice">Total price</param>
        /// <param name="totalAllotments">Total number of <c>minutes</c> or <c>case (incident)</c> allowed for the contract line.</param>
        /// <returns>
        /// Created record Id (<see cref="System.Guid"/>)
        /// </returns>
        public Guid Add(Guid contractId, CustomerType customerType, Guid customerId, string title, DateTime startDate, DateTime endDate, decimal totalPrice, int totalAllotments)
        {
            ExceptionThrow.IfGuidEmpty(contractId, "contractId");
            ExceptionThrow.IfGuidEmpty(customerId, "customerId");
            ExceptionThrow.IfNullOrEmpty(title, "title");
            ExceptionThrow.IfEquals(startDate, "startdate", DateTime.MinValue);
            ExceptionThrow.IfEquals(endDate, "endDate", DateTime.MinValue);

            Entity entity = new Entity(this.EntityName);

            entity["contractid"]      = new EntityReference("contract", contractId);
            entity["title"]           = title;
            entity["customerid"]      = new EntityReference(customerType.Description(), customerId);
            entity["activeon"]        = startDate;
            entity["expireson"]       = endDate;
            entity["price"]           = new Money(totalPrice);
            entity["totalallotments"] = totalAllotments;

            return(this.OrganizationService.Create(entity));
        }