Click here to Skip to main content
15,891,431 members
Please Sign up or sign in to vote.
3.00/5 (2 votes)
I publish my project then upload it into server here update does not work but when i run it in visual studio 2012 its work.

C#
private bool UpdateShoppingCartItemByCustomerId(int CustId)
        {
            try
            {
                bool Return = false;
                ViewCartHelper objHelper = new ViewCartHelper();
                ViewCartModel model = new ViewCartModel();
                model.GuestCustomerId = _objCustomer.Id;
                model.CustomerId = CustId;
                HttpResponseMessage response = objHelper.Update("api/ViewCart/", model);  // Blocking call!
                if (response.IsSuccessStatusCode)
                {
                    Return = true;
                }
                return Return;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
this is my controller call

controler also given bellow
C#
public bool Put(ViewCartModel model)
        {
            return repository.Update(model);
        }

My linq code is given bellow

C#
public bool Update(ViewCartModel ProductItem)
        {
            try
            {
                bool bFlag = false;
                if (ProductItem == null)
                {
                    throw new ArgumentNullException("item");
                }
                //string dtDate = System.DateTime.Now.ToString();

                using (var contextDb = new AllVetMedDbEntities())
                {
                    var query = (from Item in contextDb.ShoppingCartItems
                                 where Item.Id == ProductItem.Id
                                 select Item).SingleOrDefault();

                    var original = contextDb.ShoppingCartItems.Find(ProductItem.Id);
                    if (ProductItem.GuestCustomerId > 0)
                    {
                        var SoppingCartList = (from objcartItem in contextDb.ShoppingCartItems
                                               where objcartItem.CustomerId == ProductItem.GuestCustomerId
                                               select objcartItem).ToList();
                        SoppingCartList.ForEach(x => x.CustomerId = ProductItem.CustomerId);

                        contextDb.SaveChanges();
                        bFlag = true;

                        contextDb.SaveChanges();
                        bFlag = true;

                    }
                    else
                    {
                        if (original != null)
                        {
                            original.Quantity = ProductItem.Quantity;
                            contextDb.SaveChanges();
                            bFlag = true;
                        }
                    }
                    //}
                }


                return bFlag;
            }
            catch(Exception ex) {
                throw ex;
            }
        }
Posted
Updated 8-Jan-14 23:25pm
v2

XML
this problem has been solve by adding this on web.config file.
<modules runallmanagedmodulesforallrequests="true">
        <remove name="WebDAVModule"> **&lt;- add this**
    </remove></modules>
 
Share this answer
 
Make sure your naming conventions in your db is exactly the same as on the server. I might be wrong but looking over your code the only place I can see that it will update wrong is
C#
using (var contextDb = new AllVetMedDbEntities())
                {


It might be that the data is not updating in the db as it is not the same or does not comply with the same naming as on your pc (in debug)

_________________________EDIT______________________________________________

Also just have a look at the code in linq there is a duplicate
C#
contextDb.SaveChanges();
bFlag = true;

contextDb.SaveChanges();
bFlag = true;


You also never use the linq query...
C#
var query = (from Item in contextDb.ShoppingCartItems
             where Item.Id == ProductItem.Id
             select Item).SingleOrDefault();


But I do gather that you probably meant to do this...
C#
var query = (from Item in contextDb.ShoppingCartItems
             where Item.Id == ProductItem.Id
             select Item).SingleOrDefault();

             var original = contextDb.ShoppingCartItems.Find(query.Id);
 
Share this answer
 
v2
Comments
Rajib Mahata 9-Jan-14 9:03am    
AllVetMedDbEntities this is the name of project edmx it is right.Its do not work in web server .but it works it good localy
CBadger 10-Jan-14 1:34am    
I will have to take a look at the code and see if I am not missing something, but for now just take note of the edit I inserted into previous solution
CBadger 10-Jan-14 1:44am    
One thing I am wondering about is where you get the value for _objCustomer.Id;
ViewCartModel model = new ViewCartModel();
model.GuestCustomerId = _objCustomer.Id;
Rajib Mahata 14-Jan-14 8:14am    
this problem has been solve .
visit http://stackoverflow.com/questions/19162825/web-api-put-request-generates-an-http-405-method-not-allowed-error
CBadger 14-Jan-14 8:29am    
Good to know :-)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900