public IActionResult Post(string values) { var model = new m_Resource(); var _values = JsonConvert.DeserializeObject <IDictionary>(values); PopulateModel(model, _values); if (_context.m_Resource.Any(b => b.ItemCode == model.ItemCode)) { return(BadRequest("Item no." + model.ItemCode + " is duplicate key please check data.")); } if (model.ItemType == "F" && model.StdLotSize == null) { return(BadRequest("Std. Lot Size Required.")); } var ResourceCheck = _context.m_Resource.Where(b => b.ItemCode == model.ItemCode && b.Fcode == model.Fcode && b.Model == model.Model).Count(); if (ResourceCheck > 0) { return(BadRequest("Resource is duplicate please check data.")); } if (!TryValidateModel(model)) { return(BadRequest(GetFullErrorMessage(ModelState))); } var result = _context.m_Resource.Add(model); _context.SaveChanges(); return(Json(result.Entity.ItemCode)); }
public IActionResult Post(string values) { var model = new m_BPMaster(); var _values = JsonConvert.DeserializeObject <IDictionary>(values); PopulateModel(model, _values); if (!TryValidateModel(model)) { return(BadRequest(GetFullErrorMessage(ModelState))); } ////checked duplicate if (_context.m_BPMaster.Any(o => o.BPCode == model.BPCode)) { ModelState.AddModelError("ModelError", string.Format("BP Code {0} is duplicate key.", model.BPCode)); return(BadRequest(GetFullErrorMessage(ModelState))); } //Add Create date model.CreateDate = DateTime.Now; model.TransDate = DateTime.Now; var result = _context.m_BPMaster.Add(model); _context.SaveChanges(); return(Json(result.Entity.BPCode)); }
[HttpPost] // Create public IActionResult Post(string values, string ProcessCode, string ProcessName) { var model = new m_ProcessMaster(); var _values = JsonConvert.DeserializeObject <IDictionary>(values); var processcode = _values["ProcessCode"].ToString(); var checkinsert = _context.m_ProcessMaster.Where(p => p.ProcessCode == processcode).ToList(); if (checkinsert.Count > 0) { ModelState.AddModelError("ModelError", string.Format("This processCode have already.", model.ProcessCode)); return(BadRequest(GetFullErrorMessage(ModelState))); } else { PopulateModel(model, _values); //if (!TryValidateModel(model)) // return BadRequest(GetFullErrorMessage(ModelState)); model.SysemProcessFLag = "N"; model.AllowPartialFlag = "N"; model.SeqNo = 99; } var result = _context.m_ProcessMaster.Add(model); _context.SaveChanges(); return(Json(result.Entity.ProcessCode)); }
[HttpPost] // Create public IActionResult Post(string values) { var model = new m_Jig(); var _values = JsonConvert.DeserializeObject <IDictionary>(values); PopulateModel(model, _values); if (!TryValidateModel(model)) { return(BadRequest(GetFullErrorMessage(ModelState))); } //checked duplicate if (_context.m_Jig.Any(o => o.JigNo == model.JigNo)) { ModelState.AddModelError("ModelError", string.Format("JigNo {0} is duplicate.", model.JigNo)); return(BadRequest(GetFullErrorMessage(ModelState))); } int newJigID = 1 + _context.m_Jig.Max(p => p.JigID); model.JigID = newJigID; model.CreateDate = DateTime.Now; //// TODO edit 2 line //model.JigUserDef1 = DateTime.Today; model.ModifyBy = GetUserName(); // "FixIt"; var result = _context.m_Jig.Add(model); _context.SaveChanges(); return(Json(result.Entity.JigID)); }
public void DeleteDataRefresh(string User) { //get Token var UserToken = _context.UserTransaction.FirstOrDefault(x => x.UserName == User); if (UserToken != null) { var model = _context.isonite_temp.FirstOrDefault(item => item.user_create == User && item.Token == UserToken.Token); var sumTemp = _context.isonite_temp.Where(x => x.user_create == User).GroupBy(o => o.BarCode).Select(x => new { Barcode = x.Key, SumQty = x.Sum(i => i.QtyComplete + i.QtyNG) }).FirstOrDefault(); if (sumTemp != null) { var woRouting = _context.WoRouting.FirstOrDefault(item => item.BarCode == sumTemp.Barcode); woRouting.QTYinProcess = woRouting.QTYinProcess - sumTemp.SumQty; _context.SaveChanges(); } if (model != null) { _context.isonite_temp.Remove(model); _context.SaveChanges(); } } }
public IActionResult Post(string values) { var model = new m_BOM(); var _values = JsonConvert.DeserializeObject<IDictionary>(values); PopulateModel(model, _values); var ResourceCheck = _context.m_BOM.Where(b => b.ItemCode == model.ItemCode).Count(); if (ResourceCheck > 0) { return BadRequest("Part No duplicate please check data."); } if (model.Material1 == model.Material2) { return BadRequest("Material#1 duplicate Material#2 please check data."); } if (!TryValidateModel(model)) return BadRequest(GetFullErrorMessage(ModelState)); var result = _context.m_BOM.Add(model); _context.SaveChanges(); return Json(result.Entity.ItemCode); }
public IActionResult Delete(string IsoniteCode) { if (IsoniteCode != "") { var model = _context.Isonite.FirstOrDefault(item => item.IsoniteCode == IsoniteCode); _context.Isonite.Remove(model); _context.SaveChanges(); var model_1 = _context.Isonite_Line.Where(item => item.IsoniteCode == IsoniteCode); foreach (var r in model_1) { var wo_routing = _context.WoRouting.Where(x => x.ProcessCode == "ISONITE" && x.BarCode == r.BarCode).FirstOrDefault(); if (wo_routing != null) { wo_routing.QTYinProcess = 0; _context.SaveChanges(); } } _context.Isonite_Line.RemoveRange(model_1); _context.SaveChanges(); } return(Ok()); }
public IActionResult Print(string RowNumber) { IPHostEntry heserver = Dns.GetHostEntry(Dns.GetHostName()); var ip = heserver.AddressList[1].ToString(); var Log_Select_Print = _context.Log_Select_Print.Where(w => w.opt == "PrintWIPStatus"); //List<VW_MFC_ProductionDailyReport1> pdr = _context.VW_MFC_ProductionDailyReport1.ToList(); //List<VW_MFC_ProductionDailyReport1> pdr = _context.VW_MFC_ProductionDailyReport1.ToList(); var flag = false; if (RowNumber != null) { //HttpContext.Session.SetString("Test", FCode); // HttpContext.Session.SetString("fcode", FCode); flag = true; if (Log_Select_Print.Count() > 0) { var oldipaddress = Log_Select_Print.Where(w => w.opt == "PrintWIPStatus" && w.ipaddress == ip); if (oldipaddress.Count() > 0) { var pp_update = _context.Log_Select_Print.FirstOrDefault(f => f.opt == "PrintWIPStatus" && f.ipaddress == ip); pp_update.name = RowNumber; pp_update.ipaddress = ip; _context.Log_Select_Print.Update(pp_update); } else { var pp_insert = new Log_Select_Print { opt = "PrintWIPStatus", name = RowNumber, ipaddress = ip }; _context.Log_Select_Print.Add(pp_insert); } _context.SaveChanges(); } else { var pp_insert = new Log_Select_Print { opt = "PrintWIPStatus", name = RowNumber, ipaddress = ip }; _context.Log_Select_Print.Add(pp_insert); _context.SaveChanges(); } } //return View(pdr); return(Json(flag)); }
public IActionResult PrintProductionDailyReport1(string RowNumber, string fromdate, string todate) { IPHostEntry heserver = Dns.GetHostEntry(Dns.GetHostName()); var ip = heserver.AddressList[1].ToString(); var Log_Select_Print = _context.Log_Select_Print.Where(w => w.opt == "PrintProduction1"); var flag = false; if (RowNumber != null) { flag = true; if (Log_Select_Print.Count() > 0) { var oldipaddress = Log_Select_Print.Where(w => w.opt == "PrintProduction1" && w.ipaddress == ip); if (oldipaddress.Count() > 0) { var pp_update = _context.Log_Select_Print.FirstOrDefault(f => f.opt == "PrintProduction1" && f.ipaddress == ip); pp_update.name = RowNumber; pp_update.ipaddress = ip; _context.Log_Select_Print.Update(pp_update); } else { var pp_insert = new Log_Select_Print { opt = "PrintProduction1", name = RowNumber, ipaddress = ip }; _context.Log_Select_Print.Add(pp_insert); } _context.SaveChanges(); } else { var pp_insert = new Log_Select_Print { opt = "PrintFGMovement", name = RowNumber, ipaddress = ip }; _context.Log_Select_Print.Add(pp_insert); _context.SaveChanges(); } } //return View(pdr); return(Json(flag)); //return RedirectToAction("Index", "PrintProduction1"); //return Content("window.open('PrintProduction1/Index')"); }
public static bool Log_Print(string RowNumber, string string_process, string token, string username, NittanDBcontext _context) { var Log_Select_Print = _context.Log_Select_Print.Where(w => w.opt == string_process); var flag = false; if (RowNumber != null) { flag = true; if (Log_Select_Print.Count() > 0) { var oldipaddress = Log_Select_Print.Where(w => w.opt == string_process && w.username == username); if (oldipaddress.Count() > 0) { var pp_update = _context.Log_Select_Print.FirstOrDefault(f => f.opt == string_process && f.username == username); pp_update.name = RowNumber; pp_update.token = token; pp_update.username = username; _context.Log_Select_Print.Update(pp_update); } else { var pp_insert = new Log_Select_Print { opt = string_process, name = RowNumber, token = token, username = username }; _context.Log_Select_Print.Add(pp_insert); } _context.SaveChanges(); } else { var pp_insert = new Log_Select_Print { opt = string_process, name = RowNumber, token = token, username = username }; _context.Log_Select_Print.Add(pp_insert); _context.SaveChanges(); } } return(flag); }
public object UpadateMoveticket(DataSourceLoadOptions loadOptions, string moveticket, string PartDesType) { var identity = (ClaimsIdentity)User.Identity; IEnumerable <Claim> claims = identity.Claims; var userLogin = claims.FirstOrDefault(); var status = ""; if (moveticket != "" && PartDesType != "") { var savemoveticket = _context.MoveTicket.FirstOrDefault(m => m.moveTicket == moveticket); if (savemoveticket.moveTicket.Count() > 0) { savemoveticket.TagType = PartDesType; savemoveticket.TransDate = Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")); savemoveticket.ModifyBy = userLogin.Value; _context.MoveTicket.Update(savemoveticket); _context.SaveChanges(); status = "1"; } } else { status = "0"; } return(DataSourceLoader.Load(status, loadOptions)); }
public IActionResult Post(string values) { var model = new WeeklyPlan(); var _values = JsonConvert.DeserializeObject <IDictionary>(values); PopulateModel(model, _values); if (!TryValidateModel(model)) { return(BadRequest(GetFullErrorMessage(ModelState))); } var result = _context.WeeklyPlan.Add(model); _context.SaveChanges(); return(Json(result.Entity.BarCode)); }
public IActionResult Delete(string options) { if (options != "") { var model = _context.UserTransaction.FirstOrDefault(item => item.ID == Int32.Parse(options)); _context.UserTransaction.Remove(model); _context.SaveChanges(); } return(Ok()); }
public IActionResult Post(string values) { var model = new m_Shift(); var _values = JsonConvert.DeserializeObject <IDictionary>(values); PopulateModel(model, _values); if (!TryValidateModel(model)) { return(BadRequest(GetFullErrorMessage(ModelState))); } //checked duplicate //if (_context.m_Shift.Any(o => o.ShiftID == model.ShiftID)) //{ // ModelState.AddModelError("ModelError", string.Format("Shift Id {0} is duplicate key.", model.ShiftID)); // return BadRequest(GetFullErrorMessage(ModelState)); //} var maxValue = _context.m_Shift.Max(x => x.ShiftID); var maxRow = _context.m_Shift.First(x => x.ShiftID == maxValue); if (maxRow == null) { maxRow.ShiftID = 0; } model.ShiftID = maxRow.ShiftID + 1; //Add Create date model.CreateDate = DateTime.Now; model.TransDate = DateTime.Now; var result = _context.m_Shift.Add(model); _context.SaveChanges(); return(Json(result.Entity.ShiftID)); }
public IActionResult Reset([FromBody] ResetPassword data) { var UserCheck = context.m_UserMaster.Where(b => b.UserName == data.user && b.UserPassword == HelperClass.EncodePassword(data.CurrentPassword, "P@ssw0rd") && b.Status != "I").ToList(); if (UserCheck.Count == 1) { var model = context.m_UserMaster.Where(b => b.UserName == data.user && b.UserPassword == HelperClass.EncodePassword(data.CurrentPassword, "P@ssw0rd") && b.Status != "I").FirstOrDefault(); model.UserPassword = HelperClass.EncodePassword(data.NewPassword, "P@ssw0rd"); context.SaveChanges(); return(RedirectToAction("Index", "Home")); } else { return(new JsonResult(new { Msg = "Error", des = "Current Password do not match!" })); } }
public IActionResult Insert(string[] getitem, string UserName, string UserPassword, string FirstName, string LastName, string UserEmail, string DepID, string Status) { var identity = (ClaimsIdentity)User.Identity; IEnumerable <Claim> claims = identity.Claims; var userLogin = claims.FirstOrDefault(); //List<m_UserMaster> result = new List<m_UserMaster>(); var result = 0; var UserId = ""; switch (Status) { default: Status = "I"; break; case "Active": Status = "A"; break; case "Inactive": Status = "I"; break; } //check insert m_UserMaster var m_UM = _context.m_UserMaster.Where(u => u.UserName == UserName).ToList(); //เช็คusername ก่อน insert m_UserMaster if (m_UM.Count > 0) //username ซํ้า { result = 0; } else { var insertdep = new m_UserMaster //ถ้าไม่ซํ้าให้ insert User { UserName = UserName, UserPassword = HelperClass.EncodePassword(UserPassword, "P@ssw0rd"), FirstName = FirstName, LastName = LastName, UserEmail = UserEmail, DepID = DepID, Status = Status, TransDate = Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")), CreateDate = Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")), LastSignedin = Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")), ModifyBy = userLogin.Value, UserRoll = "USER" }; _context.m_UserMaster.Add(insertdep); _context.SaveChanges(); UserId = Convert.ToString(insertdep.UserId); m_UM = _context.m_UserMaster.Where(u => u.UserId == Convert.ToInt32(UserId)).ToList(); result = 1; //end check insert m_UserMaster //default insert m_UserPermiss dashboard //var dashboard = _context.MenuMaster.SingleOrDefault(d => d.MenuID == "DashBoard" && d.Parent_MenuID == "*"); //var defaultinsertper = new m_UserPermiss //default view dashboard //{ // UserId = UserId, // MenuIdentity = dashboard.MenuIdentity, // TransDate = Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")), // CreateDate = Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")), // ModifyBy = userLogin.Value //}; //_context.m_UserPermiss.Add(defaultinsertper); //_context.SaveChanges(); //check insert m_UserPermiss for (var a = 0; a < getitem.Length; a++) { var insertper = new m_UserPermiss { UserId = UserId, MenuIdentity = Convert.ToInt32(getitem[a].ToString()), TransDate = Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")), CreateDate = Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")), ModifyBy = userLogin.Value }; _context.m_UserPermiss.Add(insertper); _context.SaveChanges(); } }//end insert m_UserPermiss return(Json(result)); }
public IActionResult Post(string values) { var model = new m_Routing(); var _values = JsonConvert.DeserializeObject <IDictionary>(values); PopulateModel(model, _values); if (model.OperationNo <= 0) { return(BadRequest("OperationNo is negative please check data.")); } if (model.ProcessCode == "") { return(BadRequest("ProcessCode is empty please check data.")); } if (model.MachineCode == "") { return(BadRequest("MachineCode is empty please check data.")); } if (model.PiecePerMin <= 0) { return(BadRequest("PiecePerMin is not equal to 0 please check data.")); } var ResourceCheck = _context.m_Routing.Where(b => b.ItemCode == model.ItemCode && b.OperationNo == model.OperationNo).Count(); if (ResourceCheck > 0) { return(BadRequest("Part No and OperationNo duplicate please check data.")); } var ProcessCheck = _context.m_Routing.Where(b => b.ItemCode == model.ItemCode && b.ProcessCode == model.ProcessCode).Count(); if (ProcessCheck > 0) { return(BadRequest("Part No and ProcessCode duplicate please check data.")); } var OperationCheck = _context.m_Routing.Where(b => b.ItemCode == model.ItemCode).Count(); if (OperationCheck > 25) { return(BadRequest("Operation greater than 25 please check data.")); } if (model.ProcessCode == "Friction") { var Resource = _context.m_BOM.Where(b => b.ItemCode == model.ItemCode && b.Material1 == "" && b.Material2 == "").Count(); if (Resource > 0) { return(BadRequest("Process Friction Material1 and Material2 is empty please check data.")); } } if (!TryValidateModel(model)) { return(BadRequest(GetFullErrorMessage(ModelState))); } var identity = (ClaimsIdentity)User.Identity; IEnumerable <Claim> claims = identity.Claims; var c = claims.FirstOrDefault(); model.TransDate = DateTime.Now; model.CreateDate = DateTime.Now; model.ModifyBy = c.Value; var result = _context.m_Routing.Add(model); _context.SaveChanges(); return(Json(result.Entity.ItemCode)); }
public IActionResult CallStore(string model, string BoxType, string TagType, int QtyMT, int packQty, int NumOfBox, int QtyExcess) { var identity = (ClaimsIdentity)User.Identity; IEnumerable <Claim> claims = identity.Claims; var userID = claims.FirstOrDefault(); string txtMoveTicket = ""; string txtBoxNo = ""; string txtBarcode = ""; int txtQtyLot = 0; string txtStatusLot = ""; DateTime txtCreateDate; if (TagType == null) { TagType = "NULL"; } try { using (var cmd = _context.Database.GetDbConnection().CreateCommand()) { cmd.Parameters.Clear(); cmd.CommandText = "m_sp_InsertMoveticket"; cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.Add(new SqlParameter("@model", SqlDbType.NVarChar) { Value = model }); cmd.Parameters.Add(new SqlParameter("@BoxType", SqlDbType.NVarChar) { Value = BoxType }); cmd.Parameters.Add(new SqlParameter("@TagType", SqlDbType.NVarChar) { Value = TagType }); cmd.Parameters.Add(new SqlParameter("@packQty", SqlDbType.Int) { Value = packQty }); cmd.Parameters.Add(new SqlParameter("@QtyMT", SqlDbType.Int) { Value = QtyMT }); cmd.Parameters.Add(new SqlParameter("@NumOfBox", SqlDbType.Int) { Value = NumOfBox }); cmd.Parameters.Add(new SqlParameter("@QtyExcess", SqlDbType.Int) { Value = QtyExcess }); cmd.Parameters.Add(new SqlParameter("@userID", SqlDbType.NVarChar) { Value = userID.Value }); if (cmd.Connection.State != ConnectionState.Open) { cmd.Connection.Open(); } DataTable dt = new DataTable(); //dt.Columns.Add("SqlStatus", typeof(System.String)); //dt.Columns.Add("SqlErrtext", typeof(System.String)); DbDataReader DbReader = cmd.ExecuteReader(); //foreach (DataRow row in dt.Rows) //{ // row["SqlStatus"] = ""; // row["SqlErrtext"] = ""; //} if (DbReader.HasRows) { dt.Load(DbReader); foreach (DataRow dr in dt.Select()) { var wp = _context.WeeklyPlan.FirstOrDefault(w => w.BarCode == (string)dr["Barcode"]); wp.QtyPacked = wp.QtyPacked + (int)dr["QtyLot"]; wp.UpdateDate = (DateTime)dr["CreateDate"]; _context.WeeklyPlan.Update(wp); _context.SaveChanges(); if (dr["MoveTicket"] != System.DBNull.Value) { txtMoveTicket = (string)dr["MoveTicket"]; } if (dr["BoxNo"] != System.DBNull.Value) { txtBoxNo = (string)dr["BoxNo"]; } if (dr["Barcode"] != System.DBNull.Value) { txtBarcode = (string)dr["Barcode"]; } if (dr["QtyLot"] != System.DBNull.Value) { txtQtyLot = (int)dr["QtyLot"]; } if (dr["StatusLot"] != System.DBNull.Value) { txtStatusLot = (string)dr["StatusLot"]; } //if (dr["CreateDate"] != System.DBNull.Value) //{ // txtStatusMT = (DateTime)dr["CreateDate"]; //} ////txtTransDate = (DateTime)dr["TransDate"]; txtCreateDate = (DateTime)dr["CreateDate"]; //move.SqlStatus = "Success"; //move.SqlErrtext = ""; //txtModifyBy = (string)dr["ModifyBy"]; move = new MoveTicketViewModel { moveTicket = txtMoveTicket, BoxNo = txtBoxNo, Barcode = txtBarcode, QtyLot = txtQtyLot, StatusLot = txtStatusLot, CreateDate = txtCreateDate, //ModifyBy = txtModifyBy, SqlStatus = "Success", SqlErrtext = "" }; } } cmd.Connection.Close(); } } catch (SqlException ex) { move = new MoveTicketViewModel { SqlStatus = "Error", SqlErrtext = ex.Message }; } return(new JsonResult(move)); // _context.Database.ExecuteSqlCommand("dbo.m_sp_Model_Moveticket @model,@BoxType,@TagType,@QtyMT,@packQty,@NumOfBox,@QtyExcess", parameters: new[] { "KPPA INT", "B2", "T1", "850", "200", "5", "50" }); }
public async Task <IActionResult> Index(LoginViewModel model, string returnUrl = null) { ViewData["ReturnUrl"] = returnUrl; try { if (ModelState.IsValid) { ModelState.Remove("FirstName"); ModelState.Remove("LastName"); using (var context = _context) { // Query for all blogs with names starting with B var UserCheck = context.m_UserMaster.Where(b => b.UserName == model.Username && b.UserPassword == HelperClass.EncodePassword(model.Password, "P@ssw0rd") && b.Status != "I").Count(); if (UserCheck == 0) { ViewBag.UserLoginFailed = "Login Failed.Please enter correct credentials"; return(View(model)); } else { var identity = (ClaimsIdentity)User.Identity; string lastChanged; lastChanged = (from c in identity.Claims where c.Type == "ContactName" select c.Value).FirstOrDefault(); //CheckTransacTion(model.Username); //var claims = new List<Claim> { new Claim("ContactName", model.Username ?? "") }; //ClaimsIdentity userIdentity = new ClaimsIdentity(claims, "login"); //ClaimsPrincipal principal = new ClaimsPrincipal(userIdentity); //await HttpContext.SignInAsync(CookieAuthenticationDefaults.AuthenticationScheme, user); if (string.IsNullOrEmpty(lastChanged)) { // return RedirectToAction("Index", "Login"); } else { return(RedirectToAction("Index", "Home")); } // HttpContext.Session.SetString("Username", model.Username); //DbFunctions dfunc = null; if (_context.UserTransaction.Any(x => x.UserName == model.Username)) { // var model1 = _context.UserTransaction.Where(x => SqlServerDbFunctionsExtensions //.DateDiffMinute(dfunc, Convert.ToDateTime(x.DateExprie), Convert.ToDateTime(DateTime.Now)) <= 10 && x.UserName == model.Username).FirstOrDefault(); var model1 = _context.UserTransaction.Where(x => x.UserName == model.Username).FirstOrDefault(); double Minute = (DateTime.Now - (DateTime)model1.DateExprie).TotalMinutes; if (Minute <= 10) { ViewBag.UserLoginFailed = "Login Failed.Please enter correct credentials"; return(View()); } else { ClaimsPrincipal user = new ClaimsPrincipal(new ClaimsIdentity(new[] { new Claim("ContactName", model.Username ?? "") }, CookieAuthenticationDefaults.AuthenticationScheme)); await HttpContext.SignInAsync( CookieAuthenticationDefaults.AuthenticationScheme, new ClaimsPrincipal(user), new AuthenticationProperties { //CookiePath = new PathString("/Login/Logout"), IsPersistent = true, ExpiresUtc = DateTime.UtcNow.AddMinutes(10) }); var model_1 = _context.UserTransaction.FirstOrDefault(x => x.UserName == model.Username); _context.UserTransaction.Remove(model_1); _context.SaveChanges(); DeleteDataRefresh(model.Username); TempData["UserName"] = model.Username; var ToKen = Guid.NewGuid(); var Model_Tran = new UserTransaction { UserName = model.Username, Token = ToKen.ToString(), SessionKey = "", DateExprie = DateTime.Now }; _context.UserTransaction.AddRange(Model_Tran); _context.SaveChanges(); } } else { var ToKen = Guid.NewGuid(); TempData["UserName"] = model.Username; var Model_Tran = new UserTransaction { UserName = model.Username, Token = ToKen.ToString(), SessionKey = "", DateExprie = DateTime.Now }; _context.UserTransaction.AddRange(Model_Tran); _context.SaveChanges(); ClaimsPrincipal user = new ClaimsPrincipal(new ClaimsIdentity(new[] { new Claim("ContactName", model.Username ?? "") }, CookieAuthenticationDefaults.AuthenticationScheme)); await HttpContext.SignInAsync( CookieAuthenticationDefaults.AuthenticationScheme, new ClaimsPrincipal(user), new AuthenticationProperties { //CookiePath = new PathString("/Login/Logout"), IsPersistent = true, ExpiresUtc = DateTime.UtcNow.AddMinutes(10) }); } // await HttpContext.SignInAsync(principal); return(RedirectToAction("Index", "Home")); } } } else { return(View(model)); } } catch (DbUpdateConcurrencyException) { return(View(model)); } }
public IActionResult GetSearchIsonite(string JigNo, string User) { if (JigNo != "") { var model = _Context.Isonite_Line_Temp.Where(x => x.ModifyBy == User).ToList(); if (model != null) { _Context.Isonite_Line_Temp.RemoveRange(model); _Context.SaveChanges(); } List <Isonite_Line_Temp> listIsonite = new List <Isonite_Line_Temp>(); var woRoutings = (from detail in _Context.Isonite_Line join Weekly in _Context.WeeklyPlan on detail.BarCode equals Weekly.BarCode into gj from sub in gj.DefaultIfEmpty() where detail.JigNo == JigNo && detail.TransType == "Sent" select new { detail.IsoniteCode, detail.JigNo, detail.JigAddress, detail.BarCode, detail.TransType, detail.Qty, detail.RefIsoniteCode, detail.RefJigAddress, sub.Model, }).ToList(); foreach (var row in woRoutings) { listIsonite.Add( new Isonite_Line_Temp { IsoniteCode = row.IsoniteCode, JigNo = row.JigNo, JigAddress = row.JigAddress, BarCode = row.BarCode, TransType = row.TransType, Qty = row.Qty, RefIsoniteCode = row.RefIsoniteCode, RefJigAddress = row.RefJigAddress, CreateDate = DateTime.Now, TransDate = DateTime.Now, Sentdate = DateTime.Now, Receivedate = DateTime.Now, ModifyBy = User }); } _Context.Isonite_Line_Temp.AddRange(listIsonite); _Context.SaveChanges(); return(new JsonResult(new { Msg = "OK", Isonite_Line = woRoutings })); } else { return(new JsonResult(new { Msg = "ERROR", des = "Message: Isonite Code is Null." })); } }
public async Task <IActionResult> Index(LoginViewModel model, string returnUrl = null) { ViewData["ReturnUrl"] = returnUrl; try { string sessionID = HttpContext.Session.Id.ToString(); if (ModelState.IsValid) { ModelState.Remove("FirstName"); ModelState.Remove("LastName"); using (var context = _context) { // Query for all blogs with names starting with B var UserCheck = context.m_UserMaster.Where(b => b.UserName == model.Username && b.UserPassword == HelperClass.EncodePassword(model.Password, "P@ssw0rd") && b.Status != "I").Count(); if (UserCheck == 0) { ViewBag.UserLoginFailed = "Login Failed.Please enter correct credentials"; return(View(model)); } else { var identity = (ClaimsIdentity)User.Identity; string lastChanged; lastChanged = (from c in identity.Claims where c.Type == "ContactName" select c.Value).FirstOrDefault(); if (_context.UserTransaction.Any(x => x.UserName == model.Username)) //มี user ในtable UserTransaction { // var model1 = _context.UserTransaction.Where(x => SqlServerDbFunctionsExtensions //.DateDiffMinute(dfunc, Convert.ToDateTime(x.DateExprie), Convert.ToDateTime(DateTime.Now)) <= 10 && x.UserName == model.Username).FirstOrDefault(); var model1 = _context.UserTransaction.Where(x => x.UserName == model.Username).FirstOrDefault(); double Minute = (DateTime.Now - model1.DateExprie).Days; //login นานเท่าไหร่ if (Minute <= 1) //เวลายังไม่หมด { //if (string.IsNullOrEmpty(lastChanged))//เข้ามาในระบบ อีก browser หรือ อีกเครื่อง แต่มี login ค้างอยู่อีก browser //{ //ViewBag.UserLoginFailed = "time:" + Minute.ToString(); // return View(); //} //else //{ // return RedirectToAction("Index", "MainPage"); //} ClaimsPrincipal user = new ClaimsPrincipal(new ClaimsIdentity(new[] { new Claim("ContactName", model.Username ?? "") }, CookieAuthenticationDefaults.AuthenticationScheme)); await HttpContext.SignInAsync( CookieAuthenticationDefaults.AuthenticationScheme, new ClaimsPrincipal(user), new AuthenticationProperties { //CookiePath = new PathString("/Login/Logout"), IsPersistent = true, ExpiresUtc = DateTime.UtcNow.AddDays(1) }); var model_1 = _context.UserTransaction.FirstOrDefault(x => x.UserName == model.Username); model1.DateExprie = DateTime.Now; _context.SaveChanges(); return(RedirectToAction("Index", "MainPage")); } else { ClaimsPrincipal user = new ClaimsPrincipal(new ClaimsIdentity(new[] { new Claim("ContactName", model.Username ?? "") }, CookieAuthenticationDefaults.AuthenticationScheme)); await HttpContext.SignInAsync( CookieAuthenticationDefaults.AuthenticationScheme, new ClaimsPrincipal(user), new AuthenticationProperties { //CookiePath = new PathString("/Login/Logout"), IsPersistent = true, ExpiresUtc = DateTime.UtcNow.AddDays(1) }); var model_2 = _context.UserTransaction.FirstOrDefault(x => x.UserName == model.Username); _context.UserTransaction.Remove(model_2); _context.SaveChanges(); DeleteDataRefresh(model.Username); TempData["UserName"] = model.Username; var ToKen1 = Guid.NewGuid(); var Model_Tran1 = new UserTransaction { UserName = model.Username, Token = ToKen1.ToString(), SessionKey = "", DateExprie = DateTime.Now }; _context.UserTransaction.AddRange(Model_Tran1); _context.SaveChanges(); return(RedirectToAction("Index", "MainPage")); } } else // ไม่มี user ในtable UserTransaction { var ToKen = Guid.NewGuid(); TempData["UserName"] = model.Username; var Model_Tran = new UserTransaction { UserName = model.Username, Token = ToKen.ToString(), SessionKey = "", DateExprie = DateTime.Now }; _context.UserTransaction.AddRange(Model_Tran); _context.SaveChanges(); ClaimsPrincipal user = new ClaimsPrincipal(new ClaimsIdentity(new[] { new Claim("ContactName", model.Username ?? "") }, CookieAuthenticationDefaults.AuthenticationScheme)); await HttpContext.SignInAsync( CookieAuthenticationDefaults.AuthenticationScheme, new ClaimsPrincipal(user), new AuthenticationProperties { //CookiePath = new PathString("/Login/Logout"), IsPersistent = true, ExpiresUtc = DateTime.UtcNow.AddDays(1) }); //var identity1 = (ClaimsIdentity)User.Identity; //string lastChanged1; //lastChanged1 = (from c in identity1.Claims // where c.Type == "ContactName" // select c.Value).FirstOrDefault(); return(RedirectToAction("Index", "MainPage")); } } } } else { return(View(model)); } } catch (DbUpdateConcurrencyException) { return(View(model)); } }
public IActionResult Post(string values) { if (ModelState.IsValid) { return(View("SuccessValidation")); } var model = new m_Dep(); var _values = JsonConvert.DeserializeObject <IDictionary>(values); PopulateModel(model, _values); if (!TryValidateModel(model)) { return(BadRequest(GetFullErrorMessage(ModelState))); } var result = _context.m_Dep.Add(model); _context.SaveChanges(); return(Json(result.Entity.ID)); }