Example #1
0
        public ActionResult AddAddress()
        {
            OperationResult <bool> result = new OperationResult <bool>(true);

            Stream req = Request.InputStream;

            req.Seek(0, System.IO.SeekOrigin.Begin);
            string json = new StreamReader(req).ReadToEnd();

            DeliveryAddress addr = new DeliveryAddress();

            try
            {
                var clntObj = JsonConvert.DeserializeObject <dynamic>(json);
                addr.UserId        = CurrentUser.Id;
                addr.Name          = clntObj.FullName;
                addr.Mobile        = clntObj.Mobile;
                addr.Address1      = clntObj.AddressObject.AddressLine1;
                addr.Address2      = clntObj.Address2;
                addr.Suburb        = clntObj.AddressObject.Suburb;
                addr.City          = clntObj.AddressObject.CityTown;
                addr.StateOrRegion = "";
                addr.CountryCode   = "NZ";
                addr.Postcode      = clntObj.AddressObject.Postcode;
                addr.Area          = clntObj.Area;

                addr.Save(_db);
            }
            catch (Exception ex)
            {
                // Try and handle malformed POST body
                result.Succeeded = false;
                result.Message   = ex.Message;
                StallApplication.SysError("[ADD ADDR]failed to address", ex);
            }

            return(Json(result, JsonRequestBehavior.AllowGet));
        }