public ActionResult Create(UserContractLog usercontractlog)
        {
            if (ModelState.IsValid)
            {
                usercontractlog.Id = Guid.NewGuid();
                db.UserContractLogs.Add(usercontractlog);
                db.SaveChanges();
                //return RedirectToAction("Index");
                return BreadCrum.RedirectToPreviousAction(Session, ControllerName);

            }

            ViewBag.UserContractId = new SelectList(db.UserContracts, "Id", "Uri", usercontractlog.UserContractId);
            ViewBag.UserContractRedirect = new SelectList(db.UserContractRedirects, "Id", "UserAgent", usercontractlog.UserContractRedirect);
            ViewBag.UserContractUri = new SelectList(db.UserContractUris, "Id", "Uri", usercontractlog.UserContractUri);
            return View(usercontractlog);
        }
 public ActionResult Edit(UserContractLog usercontractlog)
 {
     if (ModelState.IsValid)
     {
         db.Entry(usercontractlog).State = EntityState.Modified;
         db.SaveChanges();
         return BreadCrum.RedirectToPreviousAction(Session, ControllerName);
     }
     ViewBag.UserContractId = new SelectList(db.UserContracts, "Id", "Uri", usercontractlog.UserContractId);
     ViewBag.UserContractRedirect = new SelectList(db.UserContractRedirects, "Id", "UserAgent", usercontractlog.UserContractRedirect);
     ViewBag.UserContractUri = new SelectList(db.UserContractUris, "Id", "Uri", usercontractlog.UserContractUri);
     return View(usercontractlog);
 }
        private void WriteLog(Dictionary<string, string> userAgent, string resultUri, UserContract userContract, UserContractUri userContractUri = null,
                              UserContractRedirect userContractRedirect = null)
        {
            var host = Request.UserHostAddress;
            var userContractLog = new UserContractLog
                {
                    Id = Guid.NewGuid(),
                    DateTime = DateTime.Now,
                    Host = host,
                    ResultUri = resultUri,
                    UserContractId = userContract.Id,
                    UserAgent = userAgent.Aggregate("", (current, key) => current + string.Format("{0}:{1};", key.Key, key.Value))
                };

            if (userContractUri != null)
            {
                userContractLog.UserContractUri = userContractUri.Id;
            }

            if (userContractRedirect != null)
            {
                userContractLog.UserContractRedirect = userContractRedirect.Id;
            }

            db.UserContractLogs.Add(userContractLog);
            db.SaveChanges();
        }