private void btn_Xoa_Click(object sender, EventArgs e) { using (DBcontext db = new DBcontext()) { int id = (int)this.dataGridViewNguyenLieu.CurrentRow.Cells[0].Value; if (db.NguyenLieux.Find(id) == null) { MessageBox.Show("Có lỗi xảy ra khi xóa đối tượng này." + Environment.NewLine + "Vui lòng cập nhật lại hoặc chọn một đối tượng khác."); return; } if (MessageBox.Show("Bạn có muốn xóa đối tượng này?", "xóa", MessageBoxButtons.YesNo) == DialogResult.Yes) { try { db.Database.ExecuteSqlCommand("exec pc_XoaNguyenLieu {0}", id); MessageBox.Show("Xóa thành công!"); loaddulieu(); }catch { MessageBox.Show("Khổng thể xóa vì đối tượng đăng được sử dụng tại nơi khác"); } } } }
public ActionResult Create(FormCollection collection) { ViewBag.ClientSuccess = "The Client was successufuly registered"; var db = new DBcontext(); Client newClient = new Client(); try { newClient.FirstName = Request.Form["FirstName"]; newClient.LastName = Request.Form["LastName"]; newClient.BirthDate = Convert.ToDateTime(Request.Form["BirthDate"]); newClient.Gender = Convert.ToChar(Request.Form["Gender"]); newClient.PersonalId = Convert.ToDecimal(Request.Form["PersonalId"]); db.Clients.Add(newClient); db.SaveChanges(); // TODO: Add insert logic here return(View()); } catch { return(Content("An error occured")); } }
public JsonResult getClimaticData(ClimaticPublication State) { ClimaticData data = new ClimaticData(); Session["Publication_List"] = DBcontext.getClimaticData(); data = (ClimaticData)Session["Publication_List"]; //Active or Inactive Resources if (State.pos == 1) { data.resources = data.resources.Where(x => x.pubState == 1).ToList(); } else { data = (ClimaticData)Session["Publication_List"]; List <Resource> resources = DBcontext.getResourceList(); data.resources = data.resources.Where(x => x.pubState == 0).ToList(); } if (data == null) { // show error msg return(null); } return(Json(data, JsonRequestBehavior.AllowGet)); }
public ActionResult Create(FormCollection collection) { ViewBag.ServiceSuccess = "The service has been successfuly added"; var db = new DBcontext(); var serviceServiceTypeViewModel = new ServiceServiceTypeViewModel(); serviceServiceTypeViewModel.ServiceTypes = db.ServiceTypes; try { Service service = new Service { Rate = Convert.ToDecimal(Request.Form["Service.Rate"]), BeginDate = Convert.ToDateTime(Request.Form["BeginDate"]), EndDate = Convert.ToDateTime(Request.Form["EndDate"]), ServiceTypeId = Convert.ToInt16(Request.Form["Service.ServiceTypeId"]), ClientId = Convert.ToInt16(Request.Form["Service.ClientID"]) }; if (db.Clients.Single(c => c.ID == service.ClientId).Services == null) { db.Clients.Single(c => c.ID == service.ClientId).Services = new List <Service>(); } db.Clients.Single(c => c.ID == service.ClientId).Services.Add(service); db.Services.Add(service); db.SaveChanges(); return(View(serviceServiceTypeViewModel)); } catch { return(View()); } }
public ActionResult Create(User user)// chay sau khi nhan nut create tren tren user { if (ModelState.IsValid) { var dao = new UserDAO(); var MhMd5 = common.MaHoaMD5.MD5Hash(user.Password); user.Password = MhMd5; var db = new DBcontext(); if (db.Users.Any(x => x.Username == user.Username)) { //ModelState.AddModelError("ThongBao", "Ten User nay da ton tai");// vs key la thong bao se hien ra ben html co validateMessage voi key la ThongBao SetAlert("Tên đăng nhập này đã tồn tại", "error"); } else { long id = dao.Insert(user); if (id > 0) { SetAlert("Thêm User thành công", "success"); return(RedirectToAction("Index", "User")); } else { // ModelState.AddModelError("", "Thêm user không thành công."); SetAlert("Thêm user không thành công", "error"); } } } return(View("Create")); }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IHostingEnvironment env, DBcontext databasecontext) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } else { app.UseExceptionHandler("/Home/Error"); // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts. app.UseHsts(); } databasecontext.EnsureSeedDataForContext(); app.UseHttpsRedirection(); app.UseStaticFiles(); app.UseCookiePolicy(); app.UseAuthentication(); app.UseStaticFiles(); app.UseStatusCodePages(); app.UseCors(); app.UseMvc(routes => { routes.MapRoute( name: "default", template: "{controller=Home}/{action=Index}/{id?}"); }); }
public ActionResult Create(User user) { DBcontext db = new DBcontext(); if (ModelState.IsValid) { var check = db.Users.FirstOrDefault(s => s.Email == user.Email); var checkusername = db.Users.FirstOrDefault(s => s.UserName == user.UserName); if (check == null && checkusername == null) { user.PassWord = GetMD5(user.PassWord); db.Configuration.ValidateOnSaveEnabled = false; db.Users.Add(user); db.SaveChanges(); return(RedirectToAction("Index")); } else { ViewBag.error = "xin moi nhap lai"; return(View()); } } return(View(user)); }
public ActionResult Login(string email, string password) { DBcontext db = new DBcontext(); if (ModelState.IsValid) { var f_password = GetMD5(password); var data = db.Users.Where(s => s.Email.Equals(email) && s.PassWord.Equals(f_password)).FirstOrDefault(); if (data != null) { //add session Session["UserName"] = data.UserName; Session["Email"] = data.Email; var checkAdmin = data.RoleName; if (checkAdmin == "Admin") { return(RedirectToAction("Index", "Home", new { Area = "Admin" })); } else { return(RedirectToAction("Index")); } } else { ViewBag.error = "Đăng nhập thất bại"; return(RedirectToAction("Login")); } } return(View()); }
public Card(UserManager <Customer> Manager, ICartItem cart, IOptions <PaypalSettings> settings, DBcontext bcontext) { context = bcontext; userManager = Manager; cartItem = cart; configsetting = settings.Value; }
public ActionResult UsersEdit() { string userIpAddress = this.Request.UserHostAddress; try { String email = (String)Session["email"]; email = "*****@*****.**"; if (email != null) { Users user = DBcontext.getUserByEmail(email); return(View(user)); } else { return(null); } } catch (Exception ex) { //Log error DBcontext.setPiactProblem(ex.Message, ex.StackTrace, Session["email"].ToString(), userIpAddress, "BETA"); throw; } }
private void btn_Sua_Click(object sender, EventArgs e) { using (DBcontext db = new DBcontext()) { int id = (int)this.dataGridViewNguyenLieu.CurrentRow.Cells[0].Value; if (db.NguyenLieux.Find(id) == null) { MessageBox.Show("Có lỗi xảy ra khi xóa đối tượng này." + Environment.NewLine + "Vui lòng cập nhật lại hoặc chọn một đối tượng khác."); return; } var toBeUpdated = db.NguyenLieux.Single(nl => nl.MaNL == id); toBeUpdated.TenNL = tb_TenNL.Text; toBeUpdated.GiaTien = Convert.ToInt32(numeriGiaTien.Value); toBeUpdated.SoLuong = Convert.ToDouble(numericSoLuong.Value); toBeUpdated.TenDonVi = tb_DonVi.Text; db.SaveChanges(); MessageBox.Show("Cập nhật thành công!"); loaddulieu(); } }
//Fin Login public ActionResult Confirmar(int id) { string userIpAddress = this.Request.UserHostAddress; try { String Action = ""; if (ModelState.IsValid) { if (DBcontext.InsertClient(id)) { Session["mensaje"] = "correcto"; Action = "Confirmar password correcto"; //Traking String location = "Class: " + System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name; location += "-Method: " + System.Reflection.MethodBase.GetCurrentMethod().Name; TrackLog(location, Action); return(View()); } } return(View()); } catch (Exception ex) { //Log error DBcontext.setPiactProblem(ex.Message, ex.StackTrace, "NA", userIpAddress, "BETA"); return(View()); } }
//LoggedIn //public ActionResult LoggedIn() //{ // if (Session["email"] != null) // { // return RedirectToAction("Index","Publisher"); // } // else // { // return RedirectToAction("Login"); // } //} //Logout public ActionResult LogOut() { string userIpAddress = this.Request.UserHostAddress; try { String Action = ""; if (Session["email"] != null) { //Traking Session["mensaje"] = "Logout"; Action = "Logout"; String location = "Class: " + System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name; location += "-Method: " + System.Reflection.MethodBase.GetCurrentMethod().Name; TrackLog(location, Action); Session.Abandon(); Session.Clear(); Response.Cookies.Clear(); return(RedirectToAction("Index", "Home")); } else { return(RedirectToAction("Index", "Home")); } } catch (Exception ex) { //Log error DBcontext.setPiactProblem(ex.Message, ex.StackTrace, Session["email"].ToString(), userIpAddress, "BETA"); return(RedirectToAction("Index")); } }
private void SaveNewDep() { DBcontext.Departments.Add(new Departments(_depName)); DBcontext.SaveChanges(); AllDepWithManagerName = GetAllDepsWithManagerName(); CancellProperties(); MessageBox.Show("Депортамент создан"); }
private void OnDeleteButtonExecuted(object p) { DBcontext.Employees.Remove(DBcontext.Employees.Find(empPrimaryKey)); DBcontext.SaveChanges(); AllDepWithManagerName = GetAllDepsWithManagerName(); UpdateLinkedResources(); CancelProperties(); }
public ActionResult UsersIndex(Users usuario) { try { String Action = ""; String location = ""; int perfil = 0; Int32.TryParse(Session["perfil"].ToString(), out perfil); if (validateUser(usuario) && perfil == 1) { int status = 0; Int32.TryParse(usuario.Status, out status); if (status >= 1) { usuario.Status = "0"; } else { usuario.Status = "2"; // Set Publisher by default } if (Models.DBcontext.UpdateProfileByEmail(usuario)) { Session["mensaje"] = "correcto"; Action = "correcto"; } else { Session["mensaje"] = "incorrecto"; Action = "Incorrecto"; } //Traking location = "Class: " + System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name; location += "-Method: " + System.Reflection.MethodBase.GetCurrentMethod().Name; TrackLog(location, Action); return(null); } else { Action = "No tiene permisos para desactivar usuarios"; } //Traking location = "Class: " + System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name; location += "-Method: " + System.Reflection.MethodBase.GetCurrentMethod().Name; TrackLog(location, Action); return(RedirectToAction("Index", "Login")); } catch (Exception ex) { //SAVE LOG DBcontext.setPiactProblem(ex.Message, ex.StackTrace, Session["email"].ToString(), "IP", "BETA"); return(UsersIndex()); } }
public static void EnsureSeedDataForContext(this DBcontext context) { //public static void EnsureSeedDataForContext(this DBcontext context) { if (context.Users.Any()) { return; } var users = new List <User>() { new User() { id = new Guid("0f8fad5b-d9cb-469f-a165-70867728950e"), firstName = "ab", lastName = "cd", birthDate = new DateTime(), email = "*****@*****.**", phoneNumber = "0787456789", userPrivilage = "standard" }, new User() { id = new Guid("0f8fad5b-d9cb-469f-a265-70867728950e"), firstName = "ab", lastName = "cd", birthDate = new DateTime(), email = "*****@*****.**", phoneNumber = "0787456789", userPrivilage = "standard" }, new User() { id = new Guid("0f8fad5b-d9cb-469f-a365-70867728950e"), firstName = "ab", lastName = "cd", birthDate = new DateTime(), email = "*****@*****.**", phoneNumber = "0787456789", userPrivilage = "standard" }, new User() { id = new Guid("0f8fad5b-d9cb-469f-a465-70867728950e"), firstName = "ab", lastName = "cd", birthDate = new DateTime(), email = "*****@*****.**", phoneNumber = "0787456789", userPrivilage = "standard" } }; context.Users.AddRange(users); context.SaveChanges(); }
private void dataGridViewHoaDon_CellClick(object sender, DataGridViewCellEventArgs e) { using (DBcontext db = new DBcontext()) { int id = (int)this.dataGridViewHoaDon.CurrentRow.Cells[0].Value; comboBox_NguyenLieu.SelectedValue = dataGridViewHoaDon.CurrentRow.Cells[0].Value; numeriGiaTien.Value = (int)dataGridViewHoaDon.CurrentRow.Cells[2].Value; numericSoLuong.Value = int.Parse(dataGridViewHoaDon.CurrentRow.Cells[3].Value.ToString()); } }
private void RemoveDepartment() { DBcontext.Departments.Remove(DBcontext.Departments.Find(selectedDepId)); DBcontext.SaveChanges(); AllDepWithManagerName = GetAllDepsWithManagerName(); AllEmployeesWithDepName = GetEmployeersOfTheDep(); CancellProperties(); //MessageBox.Show("Отдел удолен"); }
public HorsesController(DBcontext context) { _context = context; if (_context.Horses.Count() == 0) { _context.Horses.Add(new Horse { Name = "Test" }); _context.SaveChanges(); } }
public StableController(DBcontext context) { _context = context; if (_context.Stables.Count() == 0) { _context.Stables.Add(new Stable { Name = "Test" }); _context.SaveChanges(); } }
private void dataGridViewNguyenLieu_KeyUp(object sender, KeyEventArgs e) { using (DBcontext db = new DBcontext()) { int id = (int)this.dataGridViewNguyenLieu.CurrentRow.Cells[0].Value; NguyenLieu nl = db.NguyenLieux.SingleOrDefault(x => x.MaNL == id); tb_TenNL.Text = nl.TenNL; numeriGiaTien.Value = nl.GiaTien.Value; numericSoLuong.Value = (int)nl.SoLuong; tb_DonVi.Text = nl.TenDonVi.ToString(); } }
public UserController(DBcontext context) { _context = context; if (_context.Users.Count() == 0) { _context.Users.Add(new User { FirstName = "Test" }); _context.SaveChanges(); } }
private void RemoveManager() { var dep = DBcontext.Departments.Find(selectedDepId); dep.managerID = null; DBcontext.SaveChanges(); ManagerOfSelectedDep = null; CancellProperties(); AllDepWithManagerName = GetAllDepsWithManagerName(); // MessageBox.Show("Руководитель смещен"); }
public CategoryController(DBcontext context) { _context = context; if (_context.Categories.Count() == 0) { _context.Categories.Add(new Category { Name = "Test" }); _context.SaveChanges(); } }
// GET: Service/Create/id public ActionResult Create(int id) { var db = new DBcontext(); ViewBag.ClientId = id; var serviceServiceTypeViewModel = new ServiceServiceTypeViewModel(); serviceServiceTypeViewModel.ServiceTypes = db.ServiceTypes; return(View(serviceServiceTypeViewModel)); }
public JsonResult getPublicationInfo(ClimaticPublication data) { string userIpAddress = this.Request.UserHostAddress; try { ClimaticPublication pub = new ClimaticPublication(); if (HttpContext.Request.IsAjaxRequest()) { //get the source attribute pub = pub.getPublicationInfo(data.idResource); //NOT SOURCE YET, TODO //IF SCRAP IS 0 = not apply getScrapData if (pub.Scrap == 1) { String href = getScrapData(pub); if (href.Length <= 1) { //This below, should prevent the bad requested Publications to be displayed pub.State = 0; } else { if (pub.OriginalURL.Length == 0) { pub.source += href; } else if (href.Length >= 90) { pub.source = href; } else { //Original ID has the reference value pub.source = pub.OriginalURL += href; } } } return(Json(pub, JsonRequestBehavior.AllowGet)); } return(null); } catch (Exception ex) { //Log error DBcontext.setPiactProblem(ex.Message, ex.StackTrace, "NA", userIpAddress, "BETA"); return(null); } }
private void UpdateDep() { var entity = DBcontext.Departments.Find(selectedDepId); entity.depName = DepName; if (_depManagerID == 0 && ManagerOfSelectedDep != null) { entity.managerID = _managerOfSelectedDep.empid; } DBcontext.SaveChanges(); AllDepWithManagerName = GetAllDepsWithManagerName(); AllEmployeesWithDepName = GetEmployeersOfTheDep(); CancellProperties(); }
public JsonResult getPubOnScrolling() { if (HttpContext.Request.IsAjaxRequest()) { List <ClimaticPublication> data = new List <ClimaticPublication>(); List <ClimaticPublication> Publication_List = (List <ClimaticPublication>)Session["Publication_List"]; //int TripeIndex = 0;//count data, on every 3 publication with State on True int index = (int)Session["Index"]; string userIpAddress = this.Request.UserHostAddress; try { if (index > Publication_List.Count - 1) { return(null); } else { data.Add(Publication_List.ElementAt(index)); //Below, if next data is the contain the last item, send the current and it's all if ((index + 1) <= Publication_List.Count - 1) { data.Add(Publication_List.ElementAt(index + 1)); } //Cicle below, initialize the State of all Publications foreach (var pub in Publication_List) { pub.source += getScrapData(pub); if (pub.source == "") { pub.State = 0; } } index = index + 2; Session["Index"] = index; } } catch (Exception ex) { //Log error DBcontext.setPiactProblem(ex.Message, ex.StackTrace, "NA", userIpAddress, "BETA"); } return(Json(data, JsonRequestBehavior.AllowGet)); } return(null); }
void loaddulieu() { using (DBcontext db = new DBcontext()) { dataGridViewNguyenLieu.DataSource = (from x in db.NguyenLieux where x.LoaiTuoiKho == false select new { MaNL = x.MaNL, TenNL = x.TenNL, DonGia = x.GiaTien, SoLuong = x.SoLuong, DonVi = x.TenDonVi }).ToList(); } }