public ActionResult CommentsCreate(string cmText, string cmUrl) { if (string.IsNullOrEmpty(cmText) || string.IsNullOrEmpty(cmUrl)) { return(Json(new { result = false, message = "Отсутствуют необходимые параметры" }, JsonRequestBehavior.AllowGet)); } try { Feedback fb = new Feedback() { DateOfCreation = DateTime.Today, Comment = cmText, SbUrl = cmUrl, Status = Feedback.StateEnum.Добавлен }; //Получаем идентификатор текущего пользователя using (ApplicationDbContext aspdb = new ApplicationDbContext()) { var user = System.Web.HttpContext.Current.User.Identity.GetUserId(); fb.UserId = user; } db.Feedback.Add(fb); db.SaveChanges(); return(Json(new { result = true }, JsonRequestBehavior.AllowGet)); } catch (Exception ex) { return(Json(new { result = false, message = ex.Message }, JsonRequestBehavior.AllowGet)); } }
public ActionResult ACCreate([Bind(Include = "AccountId,BankName,MFO,AccountNumber,Status,Note,OrganizationId")] Account account) { if (ModelState.IsValid) { try { //Получаем идентификатор текущего пользователя using (ApplicationDbContext aspdb = new ApplicationDbContext()) { var user = System.Web.HttpContext.Current.User.Identity.GetUserId(); account.UserId = user; } db.Accounts.Add(account); db.SaveChanges(); TempData["MessageOK"] = "Информация добавлена"; return(RedirectToAction("ACShow")); } catch (Exception ex) { ViewBag.ErMes = ex.Message; ViewBag.ErStack = ex.StackTrace; ViewBag.ErInner = ex.InnerException.InnerException.Message; return(View("Error")); } } TempData["MessageError"] = "Ошибка валидации модели"; return(View(account)); }
public ActionResult ABCreate([Bind(Include = "AccountsBalanceId,Date,Balance,Note,AccountId")] AccountsBalance accountsBalance) { if (ModelState.IsValid) { try { //Получаем идентификатор текущего пользователя using (ApplicationDbContext aspdb = new ApplicationDbContext()) { var user = System.Web.HttpContext.Current.User.Identity.GetUserId(); accountsBalance.UserId = user; } db.AccountsBalances.Add(accountsBalance); db.SaveChanges(); TempData["MessageOK"] = "Информация добавлена"; return(RedirectToAction("ABShow")); } catch (Exception ex) { ViewBag.ErMes = ex.Message; ViewBag.ErStack = ex.StackTrace; ViewBag.ErInner = ex.InnerException.InnerException.Message; return(View("Error")); } } return(View(accountsBalance)); }
public ActionResult PDCreate([Bind(Include = "PlanDebitId,Date,Sum,ProjectId,OrganizationId,Appointment,UserId,PeriodId")] PlanDebit planDebit) { if (ModelState.IsValid) { //Запрещаем руководителям проектов добавление/редактирование планов текущего и предыдущих месяцев int NextMonth = DateTime.Today.Month + 1; int WYear = DateTime.Today.Year; if (NextMonth > 12) { NextMonth = 1; WYear += 1; } int PlanMonth = planDebit.Date.Month; int PlanYear = planDebit.Date.Year; bool isPrgManager = System.Web.HttpContext.Current.User.IsInRole("ProjectManager"); if (isPrgManager && ((PlanMonth < NextMonth && PlanYear <= DateTime.Today.Year))) { TempData["MessageError"] = "Руководителям проектов запрещено добавление/редактирование планов текущего и предыдущих месяцев"; ViewData["periodItems"] = new SelectList(db.PlanningPeriods, "PlanningPeriodId", "PeriodName"); ViewData["prgSelect"] = db.Projects.FirstOrDefault(x => x.id == planDebit.ProjectId).ShortName; ViewData["orgSelect"] = db.Organizations.FirstOrDefault(x => x.id == planDebit.OrganizationId).Title; return(View(planDebit)); } try { //Получаем идентификатор текущего пользователя using (ApplicationDbContext aspdb = new ApplicationDbContext()) { var user = System.Web.HttpContext.Current.User.Identity.GetUserId(); planDebit.UserId = user; } db.PlanDebits.Add(planDebit); db.SaveChanges(); TempData["MessageOK"] = "Информация добавлена"; return(RedirectToAction("PDShow")); } catch (Exception ex) { ViewBag.ErMes = ex.Message; ViewBag.ErStack = ex.StackTrace; ViewBag.ErInner = ex.InnerException.InnerException.Message; return(View("Error")); } } TempData["MessageError"] = "Ошибка валидации модели"; return(View(planDebit)); }
public ActionResult PPCreate([Bind(Include = "PlanningPeriodId,PeriodName")] PlanningPeriod planningPeriod) { if (ModelState.IsValid) { try { db.PlanningPeriods.Add(planningPeriod); db.SaveChanges(); TempData["MessageOK"] = "Информация добавлена"; return(RedirectToAction("PPShow")); } catch (Exception ex) { ViewBag.ErMes = ex.Message; ViewBag.ErStack = ex.StackTrace; ViewBag.ErInner = ex.InnerException.InnerException.Message; return(View("Error")); } } return(View(planningPeriod)); }
public ActionResult ADCreate([Bind(Include = "ActualDebitId,Date,Sum,ProjectId,OrganizationId,Appointment,DocNumber,ApplicationUser")] ActualDebit actualDebit) { bool AD_access_allow = Boolean.Parse(db.Settings.FirstOrDefault(z => z.SettingName == "AD_old_access").SettingValue.ToString()); if (AD_access_allow) { if (ModelState.IsValid) { try { //Получаем идентификатор текущего пользователя using (ApplicationDbContext aspdb = new ApplicationDbContext()) { var user = System.Web.HttpContext.Current.User.Identity.GetUserId(); actualDebit.UserId = user; } db.ActualDebit.Add(actualDebit); db.SaveChanges(); TempData["MessageOK"] = "Информация добавлена"; return(RedirectToAction("ADShow")); } catch (Exception ex) { ViewBag.ErMes = ex.Message; ViewBag.ErStack = ex.StackTrace; ViewBag.ErInner = ex.InnerException.InnerException.Message; return(View("Error")); } } TempData["MessageError"] = "Ошибка валидации модели"; return(View(actualDebit)); } TempData["MessageError"] = "Добавление данных запрещено настройками системы"; return(View(actualDebit)); }
public ActionResult AddBalance(string balanceDate, string currData) { if (string.IsNullOrEmpty(balanceDate) || string.IsNullOrEmpty(currData)) { return(Json(new { result = false, message = "Отсутствуют необходимые параметры" }, JsonRequestBehavior.AllowGet)); } DateTime _balanceDate = new DateTime(); if (!DateTime.TryParse(balanceDate, out _balanceDate)) { return(Json(new { result = false, message = "Неверный формат даты остатка" }, JsonRequestBehavior.AllowGet)); } try { //Получаем идентификатор текущего пользователя using (ApplicationDbContext aspdb = new ApplicationDbContext()) { string user = System.Web.HttpContext.Current.User.Identity.GetUserId(); dynamic currDataJson = JsonConvert.DeserializeObject(currData); foreach (var item in currDataJson) { Balance _balance = new Balance() { UserId = user, DateOfCreation = DateTime.Now, BalanceDate = _balanceDate, CurrencyName = item.Name, Sum = item.Value }; db.Balance.Add(_balance); } } db.SaveChanges(); return(Json(new { result = true }, JsonRequestBehavior.AllowGet)); } catch (Exception ex) { return(Json(new { result = false, message = ex.Message }, JsonRequestBehavior.AllowGet)); } }
public JsonResult WriteSetting(string pName, string pValue, string pNote) { using (ApplicationDbContext aspdb = new ApplicationDbContext()) { try { //Получаем идентификатор текущего пользователя var user = System.Web.HttpContext.Current.User.Identity.GetUserId(); Settings _set = db.Settings.FirstOrDefault(x => x.SettingName == pName); if (_set == null) { _set = new Settings(); _set.ModificationDate = DateTime.Now; _set.UserId = user; _set.SettingName = pName; _set.SettingValue = pValue; _set.Note = pNote; db.Settings.Add(_set); } else { _set.ModificationDate = DateTime.Now; _set.UserId = user; _set.SettingValue = pValue; _set.Note = pNote; db.Entry(_set).State = EntityState.Modified; } db.SaveChanges(); String _message = "Информация обновлена"; return(Json(new { Result = true, Message = _message }, JsonRequestBehavior.AllowGet)); } catch (Exception ex) { var errormessage = "Ошибка выполнения запроса!\n\r" + ex.Message + "\n\r" + ex.StackTrace; return(Json(new { Result = false, Message = errormessage }, JsonRequestBehavior.AllowGet)); } } }
public override void OnActionExecuted(ActionExecutedContext filterContext) { var request = filterContext.HttpContext.Request; bool?_resbool = null; if ((string)filterContext.Controller.TempData["LoginResult"] == "Success") { _resbool = true; } if ((string)filterContext.Controller.TempData["LoginResult"] == "Failure") { _resbool = false; } using (FRModel db = new FRModel()) { try { AspVisitor visitor = new AspVisitor() { Login = filterContext.Controller.TempData["LoginName"].ToString(), Ip = request.ServerVariables["HTTP_X_FORWARDED_FOR"] ?? request.UserHostAddress, Url = filterContext.Controller.TempData["ReturnUrl"].ToString(), Password = filterContext.Controller.TempData["Password"].ToString(), Result = _resbool, Date = DateTime.Now, }; db.AspVisitors.Add(visitor); db.SaveChanges(); } catch (Exception) { return; } } base.OnActionExecuted(filterContext); }
public JsonResult UsrWksAjax(string UserId, string WorkersIds) { var errormessage = String.Empty; var data = String.Empty; if (String.IsNullOrEmpty(UserId)) { errormessage = "Ошибка валидации модели!"; data = ""; return(Json(new { Result = false, data = data, errormessage = errormessage }, JsonRequestBehavior.AllowGet)); } try { dbModel.Database.Log = (s => System.Diagnostics.Debug.WriteLine(s)); //Debug Information==================== List <int> WksArray = JsonConvert.DeserializeObject <List <int> >(WorkersIds); List <UsrWksRelation> WksList = new List <UsrWksRelation>(); foreach (var wks in WksArray) { UsrWksRelation _wks = new UsrWksRelation { UserId = UserId, WorkerId = wks }; WksList.Add(_wks); } using (var dbContextTransaction = dbModel.Database.BeginTransaction()) { try { //Удаляем ВСЕ сопоставления выбранного пользователя из БД var DelWksList = dbModel.UsrWksRelations.Where(x => x.UserId == UserId).ToList(); var result = dbModel.UsrWksRelations.RemoveRange(DelWksList); db.SaveChanges(); //Добавляем актуальные сопоставления в БД dbModel.UsrWksRelations.AddRange(WksList); dbModel.SaveChanges(); dbContextTransaction.Commit(); return(Json(new { Result = true, data = data, errormessage = errormessage }, JsonRequestBehavior.AllowGet)); } catch (Exception exin) { dbContextTransaction.Rollback(); errormessage = "Ошибка выполнения запроса!\n\r" + exin.Message + "\n\r" + exin.StackTrace; data = ""; return(Json(new { Result = false, data = data, errormessage = errormessage }, JsonRequestBehavior.AllowGet)); } } } catch (Exception ex) { errormessage = "Ошибка выполнения запроса!\n\r" + ex.Message + "\n\r" + ex.StackTrace; data = ""; return(Json(new { Result = false, data = data, errormessage = errormessage }, JsonRequestBehavior.AllowGet)); } }