Пример #1
0
        /// <summary>
        /// Update Customer by Id.
        /// </summary>
        /// <param name = "id"></param>
        /// <param name = "customer"></param>
        /// <returns></returns>
        /// <response code="200">Returns the newly-created item</response>
        /// <response code="400">If the item is null</response>

        public IHttpActionResult Put([FromBody] Customer customer, int id)
        {
            try
            {
                if (TimeUnit.Customers.Get(id) == null)
                {
                    return(NotFound());
                }

                List <string> errors = ValidateExtensions.ValidateCustomer(customer);

                if (errors.Count > 0)
                {
                    return(Content(HttpStatusCode.BadRequest, errors));
                }

                TimeUnit.Customers.Update(customer, id);
                //customer.Image = customer.ConvertAndSave();
                TimeUnit.Save();
                Utility.Log($"CUSTOMER CONTROLLER: Put Called on Customer, Successfully updated id: {id}.", "INFO");
                return(Ok(TimeFactory.Create(customer)));
            }
            catch (Exception ex)
            {
                Utility.Log($"CUSTOMER CONTROLLER: Put Cannot be called on Customer.", "ERROR", ex);
                return(BadRequest(ex.Message));
            }
        }
Пример #2
0
        /// <summary>
        /// Insert Customer.
        /// </summary>
        /// <param name = "customer"></param>
        /// <returns></returns>
        /// <response code="200">Returns the newly-created item</response>
        /// <response code="400">If the item is null</response>

        public IHttpActionResult Post([FromBody] Customer customer)
        {
            try
            {
                List <string> errors = ValidateExtensions.ValidateCustomer(customer);

                if (errors.Count > 0)
                {
                    return(Content(HttpStatusCode.BadRequest, errors));
                }

                TimeUnit.Customers.Insert(customer);
                customer.Image = customer.ConvertAndSave();
                TimeUnit.Save();
                Utility.Log($"CUSTOMER CONTROLLER: Post Called on Customer, Successfully added: {customer.Name}.", "INFO");
                return(Ok(TimeFactory.Create(customer)));
            }
            catch (Exception ex)
            {
                Utility.Log($"CUSTOMER CONTROLLER: Post Cannot be called on Customer.", "ERROR", ex);
                return(BadRequest(ex.Message));
            }
        }