Example #1
0
        public PartialViewResult UserEdit(int id, USER_ aUser)
        {
            try
            {
                BLTServiceCaller serviceCaller = BLTServiceCaller.Instance;
                var request = new RestRequest(Method.POST);

                request.Resource = "/Users/{userID}";
                request.RequestFormat = DataFormat.Xml;
                request.AddParameter("userID", id, ParameterType.UrlSegment);
                request.AddHeader("X-HTTP-Method-Override", "PUT");

                request.XmlSerializer = new RestSharp.Serializers.DotNetXmlSerializer();
                request.AddBody(aUser);
                //request.AddHeader("Content-Type", "application/xml");
                //request.AddParameter("application/xml", request.XmlSerializer.Serialize(aMember), ParameterType.RequestBody);

                USER_ updatedUser = serviceCaller.Execute<USER_>(request);

                //populate viewdata info for organization, division and role
                if (updatedUser.ORGANIZATION_ID != null && updatedUser.ORGANIZATION_ID != 0)
                {
                    request = new RestRequest();
                    request.Resource = "/Organizations/{organizationID}";
                    request.RootElement = "ORGANIZATION";
                    request.AddParameter("organizationID", updatedUser.ORGANIZATION_ID, ParameterType.UrlSegment);
                    ViewData["Organization"] = serviceCaller.Execute<ORGANIZATION>(request).NAME;
                }
                if (updatedUser.DIVISION_ID != null && updatedUser.DIVISION_ID != 0)
                {
                    request = new RestRequest();
                    request.Resource = "/divisions/{divisionID}";
                    request.RootElement = "DIVISION";
                    request.AddParameter("divisionID", updatedUser.DIVISION_ID, ParameterType.UrlSegment);
                    ViewData["Division"] = serviceCaller.Execute<DIVISION>(request).DIVISION_NAME;
                }
                if (updatedUser != null && updatedUser.ROLE_ID != 0)
                {
                    request = new RestRequest();
                    request.Resource = "/Roles/{roleID}";
                    request.RootElement = "ROLE";
                    request.AddParameter("roleID", updatedUser.ROLE_ID, ParameterType.UrlSegment);
                    ViewData["Role"] = serviceCaller.Execute<ROLE>(request).ROLE_NAME;
                }

                return PartialView("UserDetailsPV", updatedUser);
            }
            catch (Exception e)
            {
                return PartialView(e.ToString());
            }
        }
Example #2
0
        public ActionResult UserCreate(USER_ newUser)
        {
            try
            {
                BLTServiceCaller serviceCaller = BLTServiceCaller.Instance;
                var request = new RestRequest(Method.POST);
                request.Resource = "/Users";
                request.RequestFormat = DataFormat.Xml;
                request.AddHeader("Content-Type", "application/xml");
                //Use extended serializer
                BLTWebSerializer serializer = new BLTWebSerializer();
                request.AddParameter("application/xml", serializer.Serialize<USER_>(newUser), ParameterType.RequestBody);
                USER_ createdUser = serviceCaller.Execute<USER_>(request);

                return RedirectToAction("UserDetails", new { id = createdUser.USER_ID });
            }
            catch
            {
                return View();
            }
        }