Example #1
0
        /// <summary>
        ///     Updates the billing term.
        /// </summary>
        /// <param name="updatedTerm">The updated term.</param>
        /// <returns>
        ///     An <see cref="IOpResult" /> object containing data including whether or
        ///     not the operation was successful and any error messages.
        /// </returns>
        public IOpResult UpdateBillingTerm(BillingTerm updatedTerm)
        {
            var result = new OpResult();

            try
            {
                using (var ctx = new TimeTrackerContext())
                {
                    // Update the object
                    var existingEntity = ctx.BillingTerms.First(b => b.BillingTermsId == updatedTerm.BillingTermsId);
                    ctx.Entry(existingEntity).CurrentValues.SetValues(updatedTerm);
                    ctx.SaveChanges();

                    // Return success
                    result.IsSuccessful = true;
                    return(result);
                }
            }
            catch (Exception ex)
            {
                // Return failure
                result.IsSuccessful = false;
                result.ErrorMessage = ex.Message;
                return(result);
            }
        }
Example #2
0
        /// <summary>
        ///     Adds the billing term to the database.
        /// </summary>
        /// <param name="termToAdd">The term to add.</param>
        /// <returns>
        ///     An <see cref="IOpResult" /> object containing data including whether or
        ///     not the operation was successful and any error messages.
        /// </returns>
        public IOpResult AddBillingTerm(BillingTerm termToAdd)
        {
            var result = new OpResult();

            try
            {
                using (var ctx = new TimeTrackerContext())
                {
                    // Add the object
                    ctx.BillingTerms.Add(termToAdd);
                    ctx.SaveChanges();

                    // Return success
                    result.IsSuccessful = true;
                    return(result);
                }
            }
            catch (Exception ex)
            {
                // Return failure
                result.IsSuccessful = false;
                result.ErrorMessage = ex.Message;
                return(result);
            }
        }
Example #3
0
        public ActionResult UpdateBillingTerm(BillingTerm updatedTerm)
        {
            // Update the term
            var result = _processor.UpdateBillingTerm(updatedTerm);

            // Return either the updated list or an error message
            if (result.IsSuccessful)
            {
                return(GetBillingTerms());
            }

            return(Content(result.ErrorMessage));
        }
Example #4
0
        public ActionResult AddBillingTerm(BillingTerm addedTerm)
        {
            // Add the term to the database
            var result = _processor.AddBillingTerm(addedTerm);

            // Return either the updated list or an error message
            if (result.IsSuccessful)
            {
                return(GetBillingTerms());
            }

            return(Content(result.ErrorMessage));
        }
Example #5
0
        public ActionResult SaveBillingTerm(BillingTerm term, string oper, string id)
        {
            IOpResult result;

            switch (oper)
            {
            case "edit":
                result = _processor.UpdateBillingTerm(term);
                break;

            case "add":
                result = _processor.AddBillingTerm(term);
                break;

            case "del":
                result = _processor.DeleteBillingTerm(int.Parse(id));
                break;

            default:
                result = new OpResult
                {
                    IsSuccessful = false,
                    ErrorMessage = string.Format("{0} is an unsupported operation.", oper)
                };
                break;
            }

            // Return an empty string
            if (result.IsSuccessful)
            {
                return(Content(string.Empty));
            }

            // Return the error message
            HttpContext.Response.StatusCode = 500;
            return(Content(result.ErrorMessage));
        }
Example #6
0
 /// <summary>
 /// Updates the billing term.
 /// </summary>
 /// <param name="updatedTerm">The updated term.</param>
 /// <returns>IOpResult.</returns>
 public IOpResult UpdateBillingTerm(BillingTerm updatedTerm)
 {
     return(_db.UpdateBillingTerm(updatedTerm));
 }
Example #7
0
 /// <summary>
 /// Adds the billing term.
 /// </summary>
 /// <param name="addedTerm">The added term.</param>
 /// <returns>IOpResult.</returns>
 public IOpResult AddBillingTerm(BillingTerm addedTerm)
 {
     return(_db.AddBillingTerm(addedTerm));
 }