예제 #1
0
        public async Task <object> Put(PutCustomer request)
        {
            var customer = await Db.SingleByIdAsync <Customer>(request.Id);

            customer = customer.PopulateWith(request);
            var address = customer.Address.PopulateWith(request);

            customer.Address = address;

            try
            {
                // this deadlocks/hangs
                await Db.UpdateAsync(customer);

                await Db.UpdateAsync(address);

                // this deadlocks/hangs as well
                await Db.UpdateAsync(customer).ConfigureAwait(false);

                await Db.UpdateAsync(address).ConfigureAwait(false);

                // this works
                Db.Update(customer);
                Db.Update(address);
            }
            catch (System.Exception ex)
            {
            }

            return(customer);
        }
예제 #2
0
        /// <summary>
        /// Update Customer Contact State
        /// </summary>
        /// <param name="id">id</param>
        /// <param name="ContactState">Contact State from 1 to 3</param>
        /// <returns>HttpStatusCode</returns>
        public IHttpActionResult Put([FromBody] PutCustomer customer)
        {
            if (customer.Id > 0 && customer.ContactState > 0 && customer.ContactState < 4) //verificate input data
            {
                ISession session = NHibernateHelper.GetCurrentSession();
                try
                {
                    ITransaction tx = session.BeginTransaction();

                    CCustomer customerToUpdate = session.Query <CCustomer>() //select current customer from DB
                                                 .Where(p => p.Id == customer.Id)
                                                 .FirstOrDefault();

                    customerToUpdate.ContactState = customer.ContactState; //set ContactState from PUT entity to DB entity

                    session.Update(customerToUpdate);                      //update customer

                    tx.Commit();
                }
                catch (Exception e)
                {
                    //throw new Exception("",e);
                    return(ResponseMessage(Request.CreateErrorResponse(HttpStatusCode.BadRequest, "špatné parametry")));
                }
                finally
                {
                    session.Close();
                }
            }
            else
            {
                return(ResponseMessage(Request.CreateErrorResponse(HttpStatusCode.BadRequest, "neplatné parametry")));
            }
            return(ResponseMessage(Request.CreateErrorResponse(HttpStatusCode.OK, "změna proběhla v pořádku")));
        }
예제 #3
0
        public object Put(PutCustomer request)
        {
            Customer paramCustomer = request.customer;

            if (paramCustomer != null)
            {
                try
                {
                    Db.UpdateOnly(new Customer
                    {
                        name  = paramCustomer.name,
                        phone = paramCustomer.phone
                    },
                                  onlyFields: p => new { p.name, p.phone },
                                  where : p => p.document == paramCustomer.document);


                    return(Db.Select <Customer>(Db.From <Customer>().Where(p => p.document == paramCustomer.document)));
                }catch (System.Data.SqlClient.SqlException ex)
                {
                    return(new ErrorMessageResponse {
                        error = ex.Message
                    });
                }
            }
            else
            {
                return(new PutCustomerResponse {
                    response = "Customer object can't be null"
                });
            }
        }
예제 #4
0
 public object Put(PutCustomer request)
 {
     throw new NotImplementedException();
 }