public ActionResult Create(UserModel model) { _log.Debug("Create Entered"); _log.Debug("Parameter : Model"); UserModel UserData = new UserModel(); if (ModelState.IsValid) { HttpCookie AuthCookie = Request.Cookies[FormsAuthentication.FormsCookieName]; FormsAuthenticationTicket Ticket = FormsAuthentication.Decrypt(AuthCookie.Value); RegisterModel RegisteredUserData = JsonConvert.DeserializeObject<RegisterModel>(Ticket.UserData); var DateofBirth = Convert.ToDateTime(model.Dob); JsonSerializerSettings DateFormat = new JsonSerializerSettings { DateFormatHandling = DateFormatHandling.MicrosoftDateFormat }; UserData.Fid=(RegisteredUserData.Guid); UserData.Name = (model.Name ?? string.Empty); UserData.Dob = (DateofBirth); UserData.City = (model.City ?? string.Empty); UserData.PhoneNumber = (model.PhoneNumber ?? string.Empty); UserData.EmailId = (model.EmailId ?? string.Empty); try { string Result = string.Empty; var Data =JsonConvert.DeserializeObject(Utilities.HttpRequest.GetHttpRequest(url+"UserService.svc/Add", "POST", JsonConvert.SerializeObject(UserData, DateFormat))) as JToken; if (Data != null) { Result = Data["AddUserResult"].ToString(); } _log.Debug("ADD USER RESPONSE" + Result); } catch (Exception ex) { throw ex; } return RedirectToAction("Index", "User"); } else { return View(model); } }
public ActionResult Edit(UserModel model) { _log.Debug("Edit Entered : HttpPost"); _log.Debug("Paramater UserModel model:= " + JsonConvert.SerializeObject(model)); try { if (ModelState.IsValid) { UserModel UserData = new UserModel(); var DateofBirth = Convert.ToDateTime(model.Dob); JsonSerializerSettings DateFormat = new JsonSerializerSettings { DateFormatHandling = DateFormatHandling.MicrosoftDateFormat }; HttpCookie AuthCookie = Request.Cookies[FormsAuthentication.FormsCookieName]; FormsAuthenticationTicket Ticket = FormsAuthentication.Decrypt(AuthCookie.Value); RegisterModel RegisteredUserData = JsonConvert.DeserializeObject<RegisterModel>(Ticket.UserData); UserData.Fid = RegisteredUserData.Guid; UserData.Uid = model.Uid; UserData.Name = (model.Name ?? string.Empty); UserData.Dob = (DateofBirth); UserData.City = (model.City ?? string.Empty); UserData.PhoneNumber = (model.PhoneNumber ?? string.Empty); UserData.EmailId = (model.EmailId ?? string.Empty); string Result=string.Empty; var Data = JsonConvert.DeserializeObject(Utilities.HttpRequest.GetHttpRequest(url + "UserService.svc/Update", "POST", JsonConvert.SerializeObject(UserData, DateFormat))) as JToken; if (Data != null) { Result = Data["UpdateUserResult"].ToString(); } _log.Debug("Edit User result=" + Result); } else { return View(model); } } catch (Exception ex) { _log.Error("Error in Updating the table : " + ex); return RedirectToAction("ErrorPage", "Home", new { ex = ex.Message }); } finally { _log.Debug("Edit Exited"); } return RedirectToAction("Index", "User"); }