public async Task <ActionResult> Registration(Registration registration) { if (ModelState.IsValid) { UserAccount userAccount = null; using (WebAppDbContext db = new WebAppDbContext()) { userAccount = await db.UserAccounts.FirstOrDefaultAsync(u => u.UserName == registration.UserName); } if (userAccount == null) { using (WebAppDbContext db = new WebAppDbContext()) { db.UserAccounts.Add(new UserAccount { UserName = registration.UserName, Email = registration.Email, Password = registration.Password, PasswordConfirm = registration.PasswordConfirm, Name = registration.Name, Surname = registration.Surname, Year = registration.Year, RoleID = 2 }); await db.SaveChangesAsync(); userAccount = await db.UserAccounts.Where(u => u.UserName == registration.UserName && u.Password == registration.Password).FirstOrDefaultAsync(); } if (userAccount != null) { FormsAuthentication.SetAuthCookie(registration.UserName, true); return(RedirectToAction("Index", "Home")); } } else { ModelState.AddModelError("", "Пользователь с таким логином уже существует"); } } return(View(registration)); }
public ActionResult ConfigEquipIndex() { var vm = new ConfigViewModel(); string actionName = "ConfigEquipIndex"; _logger.Log(LogLevel.Trace, actionName + " :: started."); try { SessionKeys.LoadTablesInSession(SessionKeys.ApplicableUnits, "", ""); vm._tbl_Unit = ((List <ClassLibrary.Models.tbl_Unit>)Session[SessionKeys.ApplicableUnits]); vm.selectedData = "0"; using (var db = new WebAppDbContext()) { vm.tbl_Parts_list = db.tbl_Parts.Where(x => x.Status == "Active" && (x.PartTypeID == "X" || x.PartTypeID == "A")).ToList(); vm._M_PMS = db.M_PMS.ToList(); } } catch (Exception ex) { _logger.Log(LogLevel.Error, actionName + " EXCEPTION :: " + ex.ToString() + " INNER EXCEPTION :: " + ex.InnerException?.ToString()); } _logger.Log(LogLevel.Trace, actionName + " :: Ended."); return(View("ConfigEquipIndex", vm)); }
public ActionResult GetDataEmp() { db = new WebAppDbContext(); // List <decimal> empPrice = new List <decimal>(); List <decimal> empPriceinDate = new List <decimal>(); List <decimal> empTotalinDate = new List <decimal>(); List <decimal> empPriceinMonth = new List <decimal>(); List <decimal> empPriceinYear = new List <decimal>(); List <decimal> empCount = new List <decimal>(); List <decimal> empCountinDate = new List <decimal>(); List <decimal> empCountinMonth = new List <decimal>(); List <decimal> empCountinYear = new List <decimal>(); var dep = db.DailyEmployees.Where(x => x.Employee.Department_ID == 4).Select(x => x.Employee.Code).Distinct().ToList(); foreach (var item in dep) { empPriceinMonth.Add(db.DailyEmployees.Where(x => x.Employee.Code == item && x.Date.Month == DateTime.Today.Month && x.Date.Year == DateTime.Today.Year).Sum(x => x.Tip)); empCountinMonth.Add(db.DailyEmployees.Where(x => x.Employee.Code == item && x.Date.Month == DateTime.Today.Month && x.Date.Year == DateTime.Today.Year).Count()); } ViewBag.ticketCount = empCountinMonth; ViewBag.deparmentName = dep; ViewBag.ticketPrice = empPriceinMonth; return(View()); }
public ActionResult Details(string id) { string actionName = "Details"; M_PMS response = new M_PMS(); try { _logger.Log(LogLevel.Trace, actionName + " :: started."); if (String.IsNullOrWhiteSpace(id)) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } else { using (WebAppDbContext db = new WebAppDbContext()) { response = db.M_PMS.FirstOrDefault(x => x.PMS_NO == id); } } _logger.Log(LogLevel.Trace, actionName + " :: ended."); } catch (Exception ex) { _logger.Log(LogLevel.Error, actionName + " EXCEPTION :: " + ex.ToString() + " INNER EXCEPTION :: " + ex.InnerException?.ToString()); } return(PartialView("_Details", response)); }
public ActionResult List() { WebAppDbContext db = new WebAppDbContext(); var list = db.tbl_Category.ToList(); return(View(list)); }
public object GetSFD(DataSourceLoadOptions loadOptions) { using (var db = new WebAppDbContext()) { return(DataSourceLoader.Load(db.V_SFD.ToList(), loadOptions)); } }
public void Callback_WrongToken() { var dbContext = new WebAppDbContext(); var httpContext = new Mock <HttpContextBase>(); var request = new Mock <HttpRequestBase>(); var headers = new NameValueCollection(); headers.Add("X-Fourth-Token", Guid.NewGuid().ToString()); request.Setup(r => r.Headers).Returns(headers); httpContext.Setup(c => c.Request).Returns(request.Object); var subscriber = new TestClientSubscriber(); var controller = new HomeController(dbContext, subscriber); var controllerContext = new ControllerContext(new RequestContext(httpContext.Object, new RouteData()), controller); controller.ControllerContext = controllerContext; var employees = new List <EmployeeDTO> { new EmployeeDTO { EmployeeID = 1, When = DateTime.UtcNow } }; var result = controller.Callback(employees) as HttpStatusCodeResult; Assert.AreEqual((int)HttpStatusCode.Unauthorized, result.StatusCode); }
public ConfigViewModel GetSiteConfigTree(int?Id) { var viewModel = new ConfigViewModel(); using (var db = new WebAppDbContext()) { if (Id > 0) { if (IsValidSiteId(Id)) { List <TreeViewNode> nodesSite = new List <TreeViewNode>(); foreach (C_Site_Config c in db.C_Site_Config.Where(x => x.SiteId == Id)) { if (c.PESWBS == "0") { c.PESWBS = "#"; } nodesSite.Add(new TreeViewNode { id = c.ESWBS.ToString(), parent = c.PESWBS.ToString(), text = (c.ESWBS + " - " + c.Nomanclature), Name = c.Nomanclature }); } //Serialize to JSON string. viewModel.JsonSiteConfig = (new JavaScriptSerializer()).Serialize(nodesSite); } } } return(viewModel); }
public ActionResult Edit(int id) { WebAppDbContext db = new WebAppDbContext(); var category = db.tbl_Category.Find(id); return(View(category)); }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IWebHostEnvironment env, WebAppDbContext dbContext) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } else { // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts. app.UseHsts(); } app.UseOpenApi(); app.UseSwaggerUi3(); app.UseHttpsRedirection(); app.UseStaticFiles(); app.UseRouting(); app.UseCors("CorsPolicy"); app.UseMiddleware <TestMiddleware>(); app.UseEndpoints(options => { options.MapDefaultControllerRoute(); options.MapRazorPages(); options.MapHub <TestHub>("/testhub"); }); DataSeeder.Seed(dbContext); }
public JsonResult CageCodeCheck(string CageCode) { string actionName = "CageCodeCheck"; int response = 0; _logger.Log(LogLevel.Trace, actionName + " :: started."); try { if (!String.IsNullOrWhiteSpace(CageCode)) { using (var db = new WebAppDbContext()) { if (db.tbl_Cage.Any(x => x.CageCode == CageCode)) { response = 1; } } } else { _logger.Log(LogLevel.Error, actionName + " :: Cage Code is empty."); } } catch (Exception ex) { _logger.Log(LogLevel.Error, actionName + " EXCEPTION :: " + ex.ToString() + " INNER EXCEPTION :: " + ex.InnerException?.ToString()); } _logger.Log(LogLevel.Trace, actionName + " :: ended."); return(Json(response)); }
public JsonResult PartNoCheck(string CageCode, string PartNo) { string actionName = "Index"; int response = 0; try { _logger.Log(LogLevel.Trace, actionName + " :: started."); if (!String.IsNullOrWhiteSpace(CageCode) && !String.IsNullOrWhiteSpace(PartNo)) { using (WebAppDbContext db = new WebAppDbContext()) { var SearchData = db.tbl_Parts.Where(x => x.Part_No == PartNo && x.CageCode == CageCode).SingleOrDefault(); if (SearchData != null) { response = 1; } } } } catch (Exception ex) { _logger.Log(LogLevel.Error, actionName + " EXCEPTION :: " + ex.ToString() + " INNER EXCEPTION :: " + ex.InnerException?.ToString()); } _logger.Log(LogLevel.Trace, actionName + " :: ended."); return(Json(response)); }
public ActionResult Delete2(int id, FormCollection collection) { using (var db = new WebAppDbContext()) { using (var transaction = db.Database.BeginTransaction()) { try { if (id <= 0) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } var result = db.tbl_Parts.Where(x => x.PartId == id).SingleOrDefault(); if (result != null) { //Remove from award db.tbl_Parts.Remove(result); db.SaveChanges(); transaction.Commit(); } Alert("Record Deleted Permanently!!!", NotificationType.success); return(RedirectToAction("Index")); } catch (Exception ex) { transaction.Rollback(); Exception(ex); Alert("Their is something went wrong!!!", NotificationType.error); return(RedirectToAction("Index")); } } } }
public ActionResult MMS5() { try { using (WebAppDbContext _entities = new WebAppDbContext()) { var data = _entities.V_MMS5.ToList().Select(x => new { SHIP_NAME = x.Name, PMS_NO = x.PMS_No, MOP_NO = x.MOP_No, DOC = x.Doc, JIC = x.Jic, BY_WHOM = x.By_Whom, PERIODICITY = x.Periodicity?.ToString(), EQUIPMENT_NAME = x.PART_NAME, MODEL = x.Model, DESCRIPTION = x.MOP_Desc }).ToList(); return(LoadReport(Reports.MMS5, data)); } } catch (Exception ex) { _logger.Log(LogLevel.Error, "Exception :: " + ex.ToString()); } return(null); }
public ActionResult Create() { string actionName = "Create"; PartsViewModels response = new PartsViewModels(); try { _logger.Log(LogLevel.Trace, actionName + " :: started."); using (var db = new WebAppDbContext()) { response = new PartsViewModels { _tbl_Cage = db.tbl_Cage.ToList(), _tbl_PartType = db.tbl_PartType.ToList(), _tbl_MCAT = db.tbl_MCAT.ToList(), _tbl_Currency = db.tbl_Currency.ToList(), }; } } catch (Exception ex) { _logger.Log(LogLevel.Error, actionName + " EXCEPTION :: " + ex.ToString() + " INNER EXCEPTION :: " + ex.InnerException?.ToString()); } _logger.Log(LogLevel.Trace, actionName + " :: ended."); return(PartialView("_Create", response)); }
public ActionResult Edit(int id, tbl_Cage tbl_Cage) { string actionName = "Edit"; _logger.Log(LogLevel.Trace, actionName + " :: started."); try { if (ModelState.IsValid) { if (id <= 0) { Alert("Invalid Cage Selected.", NotificationType.error); _logger.Log(LogLevel.Trace, actionName + " :: Ended. Invalid cage id : " + id); return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } using (var db = new WebAppDbContext()) { var cage = db.tbl_Cage.FirstOrDefault(x => x.CageId == id); if (cage != null && (cage?.CageCode == tbl_Cage.CageCode)) { cage.CageName = tbl_Cage.CageName; cage.Address = tbl_Cage.Address; cage.Country = tbl_Cage.Country; cage.City = tbl_Cage.City; cage.PostalCode = tbl_Cage.PostalCode; cage.Status = tbl_Cage.Status; cage.ModifiedByUser = Session[SessionKeys.UserId]?.ToString(); cage.ModifiedOnDate = DateTime.Now; db.Entry(cage).State = EntityState.Modified; db.SaveChanges(); Alert("Record Updated Successfully.", NotificationType.success); } else { Alert("Cage Not Found.", NotificationType.error); _logger.Log(LogLevel.Trace, actionName + " :: Ended. Cage not found for cage id : " + id); } } } else { _logger.Log(LogLevel.Trace, actionName + " :: Ended. Model state is not valid for cage id : " + id); CageViewModels objCageViewModels = GetCage(id); return(PartialView("_Edit", objCageViewModels)); } } catch (Exception ex) { Alert("Something Went Wrong !!!", NotificationType.error); _logger.Log(LogLevel.Error, actionName + " EXCEPTION :: " + ex.ToString() + " INNER EXCEPTION :: " + ex.InnerException?.ToString()); Exception(ex); } return(RedirectToAction("Index")); }
public MopViewModels GetMopData(int?SiteId, string eswbs) { using (var db = new WebAppDbContext()) { var vm = new MopViewModels(); if (SiteId != null && eswbs != null) { var data = db.C_Site_Config.Where(x => x.SiteId == SiteId && x.ESWBS == eswbs).FirstOrDefault(); if (data.PMS_No != null) { var result = db.M_MOP.Where(x => x.PMS_No == data.PMS_No).ToList().Select(x => new M_MOPModel { SiteId = x.SiteId, PMS_No = x.PMS_No, MOP_No = x.MOP_No, MOP_Desc = x.MOP_Desc, By_Whom = x.By_Whom, PeriodMonth = x.Periodicity + " " + x.Period, mmsDoc = "MMS " + x.Doc, }); vm.M_MOPModel_List = result.ToList(); vm.pmsNo = data.PMS_No; } } return(vm); } }
public JsonResult SaveAsDashboard(string dashboardId, string userId, string roleId) { var type = "success"; var msg = "Dashboard added successfully"; try { using (var context = new WebAppDbContext()) { UserDashboardMapping model = new UserDashboardMapping() { DashboardId = dashboardId, UserId = userId, RoleId = roleId, IsDefault = "0", InsertionDateTime = DateTime.Now, InsertedBy = Session[SessionKeys.UserId].ToString() }; context.UserDashboardMappings.Add(model); context.SaveChanges(); } } catch (Exception ex) { type = "error"; msg = ex.ToString(); } return(Json(new { type = type, msg = msg }, JsonRequestBehavior.AllowGet)); }
public dynamic GetDashboards(string userId, string roleId) { dynamic response = null; if (!string.IsNullOrWhiteSpace(userId) && !string.IsNullOrWhiteSpace(roleId)) { using (var context = new WebAppDbContext()) { CustomDashboardStorage dashboardStorage = new CustomDashboardStorage(); var dashboardsInfo = dashboardStorage.GetAvailableDashboardsInfo(); if (roleId == AllRoles) { response = dashboardsInfo.Select(x => new { DashId = x.ID, DashName = x.Name }).ToList(); } else { response = dashboardsInfo.Where(y => !context.UserDashboardMappings.Where(x => x.RoleId == roleId && x.UserId == userId).Select(x => x.DashboardId).Contains(y.ID)).Select(y => new { DashId = y.ID, DashName = y.Name }).ToList(); } } } return(response); }
public ActionResult Edit(string id, tbl_MCAT tbl_MCAT) { try { if (id == null) { return new HttpStatusCodeResult(HttpStatusCode.BadRequest); } // TODO: Add update logic here using (WebAppDbContext db = new WebAppDbContext()) { if (!ModelState.IsValid) { return PartialView("_Edit"); } db.Entry(tbl_MCAT).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); } Alert("Record Updated Sucessfully!!!", NotificationType.success); return RedirectToAction("Index"); } catch { Alert("Their is something went wrong!!!", NotificationType.error); return RedirectToAction("Index"); } }
public ActionResult Create(M_PMS M_PMS) { string actionName = "Create"; try { _logger.Log(LogLevel.Trace, actionName + " :: started."); if (ModelState.IsValid) { using (WebAppDbContext db = new WebAppDbContext()) { db.M_PMS.Add(M_PMS); db.SaveChanges(); } _logger.Log(LogLevel.Trace, actionName + " :: ended."); Alert("Data Saved Sucessfully!!!", NotificationType.success); return(RedirectToAction("Index")); } else { _logger.Log(LogLevel.Trace, actionName + " :: ended."); return(PartialView("_Create")); } } catch (Exception ex) { _logger.Log(LogLevel.Error, actionName + " EXCEPTION :: " + ex.ToString() + " INNER EXCEPTION :: " + ex.InnerException?.ToString()); Alert("Their is something went wrong!!!", NotificationType.error); return(RedirectToAction("Index")); } }
private static async Task SeedRoleAsync(WebAppDbContext dbContext, string sportName, string[] positions) { if (!dbContext.Sports.Any(s => s.Name == sportName)) { Sport sport = new Sport() { Name = sportName }; foreach (var position in positions) { if (!sport.Positions.Any(p => p.Name == position)) { sport.Positions.Add(new Position() { Name = position, }); } } await dbContext.Sports.AddAsync(sport); } await dbContext.SaveChangesAsync(); }
public ActionResult Create(tbl_Cage tbl_Cage) { string actionName = "Create"; _logger.Log(LogLevel.Trace, actionName + " :: started."); try { if (ModelState.IsValid) { using (var db = new WebAppDbContext()) { if (!db.tbl_Cage.Any(x => x.CageCode == tbl_Cage.CageCode)) { // Get Current user Id var userId = Session[SessionKeys.UserId]?.ToString(); tbl_Cage.CreatedByUser = userId; tbl_Cage.ModifiedByUser = userId; //Get Current Date & Time. tbl_Cage.CreatedOnDate = DateTime.Now; tbl_Cage.ModifiedOnDate = DateTime.Now; tbl_Cage.Status = "Active"; db.tbl_Cage.Add(tbl_Cage); db.SaveChanges(); Alert("Record Added Successfully !! ", NotificationType.success); } else { _logger.Log(LogLevel.Trace, actionName + " :: Cage code : " + tbl_Cage.CageCode + " already exist."); Alert("Cage code already exist.", NotificationType.error); } } } else { CageViewModels vm = new CageViewModels(); SessionKeys.LoadTablesInSession(SessionKeys.Countries, "", ""); vm._tbl_Country = ((List <ClassLibrary.Models.tbl_Country>)Session[SessionKeys.Countries]); _logger.Log(LogLevel.Trace, actionName + " :: Model state not valid."); return(PartialView("_Create", vm)); } } catch (Exception ex) { Alert("Their is something went wrong!!!", NotificationType.error); _logger.Log(LogLevel.Error, actionName + " EXCEPTION :: " + ex.ToString() + " INNER EXCEPTION :: " + ex.InnerException?.ToString()); Exception(ex); } _logger.Log(LogLevel.Trace, actionName + " :: ended."); return(RedirectToAction("Index")); }
// GET: AwardType public ActionResult Index() { using (WebAppDbContext db = new WebAppDbContext()) { var abc = db.tbl_MCAT.ToList(); return View(abc); } }
public ActionResult Edit(tbl_Category category) { WebAppDbContext db = new WebAppDbContext(); db.Entry(category).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); return(RedirectToAction("List")); }
public ChatHub(WebAppDbContext context) { _logger = NLog.LogManager.GetCurrentClassLogger(); _context = context; // Przy wywołaniu konstruktora kontekst jest nullem. //var userId = this.Context.UserIdentifier; //var u2 = this.Context.User.Identity; }
public ActionResult EditClientDashboard(string userId, string roleId, string dashboardId) { using (var context = new WebAppDbContext()) { var response = context.UserDashboardMappings.FirstOrDefault(x => x.UserId == userId && x.RoleId == roleId && x.DashboardId == dashboardId); return(View("ClientMode", response)); } }
public void Index() { var dbContext = new WebAppDbContext(); var subscriber = new TestClientSubscriber(); var controller = new HomeController(dbContext, subscriber); var result = controller.Index() as ViewResult; Assert.IsNotNull(result); }
public ActionResult Delete(int id) { WebAppDbContext db = new WebAppDbContext(); var category = db.tbl_Category.Find(id); db.tbl_Category.Remove(category); db.SaveChanges(); return(RedirectToAction("List")); }
public ActionResult GetMOP(string PMS_No) { using (var db = new WebAppDbContext()) { List <M_MOP> M_MOP = db.M_MOP.Where(x => x.PMS_No == PMS_No).ToList(); ViewBag.M_MOP = new SelectList(M_MOP, "MOP_No", "MOP_No"); return(PartialView("_DisplayMOPs")); } }
public StudentService(WebAppDbContext dbContext) { db = dbContext; }