public async Task <ResponseModel> AllocateCall(AllocateCallModel allocateCalls) { XmlSerializer xsSubmit = new XmlSerializer(allocateCalls.SelectedDevices.GetType()); string xml = ""; using (var sww = new StringWriter()) { using (XmlWriter writer = XmlWriter.Create(sww)) { xsSubmit.Serialize(writer, allocateCalls.SelectedDevices); xml = sww.ToString(); // Your XML } } //Remove the title element. xml = xml.Replace("<?xml version=\"1.0\" encoding=\"utf-16\"?>", ""); List <SqlParameter> sp = new List <SqlParameter>(); SqlParameter param = new SqlParameter("@AllocateId", ToDBNull(allocateCalls.AllocateId)); sp.Add(param); param = new SqlParameter("@AllocateXML", SqlDbType.Xml) { Value = xml }; sp.Add(param); param = new SqlParameter("@AllocateTo", ToDBNull(allocateCalls.AllocateTo)); sp.Add(param); param = new SqlParameter("@USER", ToDBNull(allocateCalls.UserId)); sp.Add(param); var sql = "ALLOCATECALL @AllocateId,@AllocateXML,@AllocateTo,@USER"; var res = await _context.Database.SqlQuery <ResponseModel>(sql, sp.ToArray()).SingleOrDefaultAsync(); if (res.ResponseCode == 0) { res.IsSuccess = true; } else { res.IsSuccess = false; } return(res); }
public async Task <ActionResult> Allocate(AllocateCallModel allocate) { try { allocate.AllocateTo = "ASP"; allocate.UserId = CurrentUser.UserId; var response = await _customerSupport.AllocateCall(allocate); TempData["response"] = response; return(Json("Ok", JsonRequestBehavior.AllowGet)); } catch (Exception ex) { var response = new ResponseModel { Response = ex.Message, IsSuccess = false }; TempData["response"] = response; return(Json("ex", JsonRequestBehavior.AllowGet)); } }