public ActionResult AddItem(Item itm) { using (EntitiesAPSCS db = new EntitiesAPSCS()) { if (itm.ItemID == 0) { if (db.Items.Any(x => x.ItemPart == itm.ItemPart)) { return(Json(new { success = false, message = "Item Part Number Already Exist!" }, JsonRequestBehavior.AllowGet)); } else { db.Items.Add(itm); db.SaveChanges(); return(Json(new { success = true, message = "Saved Successfully" }, JsonRequestBehavior.AllowGet)); } } else { db.Entry(itm).State = EntityState.Modified; db.SaveChanges(); return(Json(new { success = true, message = "Updated Successfully" }, JsonRequestBehavior.AllowGet)); } } }
public ActionResult AddUsers(User usr) { using (EntitiesAPSCS db = new EntitiesAPSCS()) { if (usr.UserID == 0) { // check input ID is already exist if (db.Users.Any(x => x.IDCard == usr.IDCard)) { return(Json(new { success = false, message = "IDCard Number Already Exist!" }, JsonRequestBehavior.AllowGet)); } else { // New user added db.Users.Add(usr); db.SaveChanges(); return(Json(new { success = true, message = "Saved Successfully" }, JsonRequestBehavior.AllowGet)); } } else {// Edit user updated db.Entry(usr).State = EntityState.Modified; db.SaveChanges(); return(Json(new { success = true, message = "Updated Successfully" }, JsonRequestBehavior.AllowGet)); } } }
public ActionResult UserUpdateStock(Item itm) { using (EntitiesAPSCS db = new EntitiesAPSCS()) { var PartIDmatch = db.Items.Any(x => x.ItemPart.Equals(itm.ItemPart)); if (PartIDmatch == true && itm.ItemQuantity != null) { var abc = db.Items.FirstOrDefault(x => x.ItemPart == itm.ItemPart); abc.ItemQuantity = itm.ItemQuantity.Value + abc.ItemQuantity; db.SaveChanges(); ViewBag.Message = String.Format("Part Number Quantity Updated Successfully!"); } else { ViewBag.Message = String.Format("Please Enter Quantity And A Valid Part Number"); } return(View()); } }
public ActionResult ResetPassword(ResetPasswordModel model) { var message = ""; if (ModelState.IsValid) { using (var context = new EntitiesAPSCS()) { var user = context.Users.Where(a => a.ResetPasswordCode == model.ResetCode).FirstOrDefault(); if (user != null) { // Hash Password string HashedPassword = GenerateSHA256Hash(model.ConfirmPassword); user.Password = HashedPassword; //make resetpasswordcode empty string now user.ResetPasswordCode = ""; //to avoid validation issues, disable it context.Configuration.ValidateOnSaveEnabled = false; context.SaveChanges(); message = "New password was successfully updated"; } } } else { message = "Error Updating Password!"; } ViewBag.Message = message; return(View(model)); }
public ActionResult AddOrEditSupplier(Supplier emp) { using (EntitiesAPSCS db = new EntitiesAPSCS()) { if (emp.SupplierID == 0) { db.Suppliers.Add(emp); db.SaveChanges(); return(Json(new { success = true, message = "Saved Successfully" }, JsonRequestBehavior.AllowGet)); } else { db.Entry(emp).State = EntityState.Modified; db.SaveChanges(); return(Json(new { success = true, message = "Updated Successfully" }, JsonRequestBehavior.AllowGet)); } } }
public ActionResult EditItem(Item itm) { using (EntitiesAPSCS db = new EntitiesAPSCS()) { db.Entry(itm).State = EntityState.Modified; db.SaveChanges(); return(Json(new { success = true, message = "Updated Successfully" }, JsonRequestBehavior.AllowGet)); } }
public ActionResult Delete(int id) { using (EntitiesAPSCS db = new EntitiesAPSCS()) { Supplier emp = db.Suppliers.Where(x => x.SupplierID == id).FirstOrDefault <Supplier>(); db.Suppliers.Remove(emp); db.SaveChanges(); return(Json(new { success = true, message = "Deleted Successfully" }, JsonRequestBehavior.AllowGet)); } }
public ActionResult DeleteItem(int id) { using (EntitiesAPSCS db = new EntitiesAPSCS()) { Item itm = db.Items.Where(x => x.ItemID == id).FirstOrDefault <Item>(); db.Items.Remove(itm); db.SaveChanges(); return(Json(new { success = true, message = "Deleted Successfully" }, JsonRequestBehavior.AllowGet)); } }
public ActionResult DeleteStockOut(int id, StockOut stkout) { using (EntitiesAPSCS db = new EntitiesAPSCS()) { stkout = db.StockOuts.Where(x => x.StockOutID == id).FirstOrDefault <StockOut>(); var GetItem = db.Items.FirstOrDefault(x => x.ItemPart == stkout.StockOutPart); var GetSqty = db.StockOuts.FirstOrDefault(x => x.StockOutPart == stkout.StockOutPart); GetItem.ItemQuantity = GetItem.ItemQuantity + GetSqty.StockOutQuantity.Value; db.StockOuts.Remove(stkout); db.SaveChanges(); return(Json(new { success = true, message = "Record Deleted Successfully. Stock Quantity Updated!" }, JsonRequestBehavior.AllowGet)); } }
public ActionResult EditStockOut(StockOut stkout) { using (EntitiesAPSCS db = new EntitiesAPSCS()) { var stkoutID = db.StockOuts.Find(stkout.StockOutID); var PartIDmatch = db.Items.Any(x => x.ItemPart.Equals(stkout.StockOutPart)); var GetItem = db.Items.FirstOrDefault(x => x.ItemPart == stkout.StockOutPart); var GetSqty = db.StockOuts.FirstOrDefault(x => x.StockOutPart == stkout.StockOutPart); if (!db.Items.Any(x => x.ItemPart == stkout.StockOutPart)) { return(Json(new { success = false, message = "Item Part Number Not Found!" }, JsonRequestBehavior.AllowGet)); } //else if (GetItem.ItemQuantity <= 10) //{ //} else if (stkout.StockOutQuantity > GetItem.ItemQuantity) { return(Json(new { success = false, message = "Not Enough Stock Quantity!" }, JsonRequestBehavior.AllowGet)); } else if (PartIDmatch == true && stkout.StockOutQuantity != null) { GetItem.ItemQuantity = (GetItem.ItemQuantity + GetSqty.StockOutQuantity.Value) - stkout.StockOutQuantity.Value; db.Entry(stkoutID).CurrentValues.SetValues(stkout); db.Entry(stkoutID).State = EntityState.Modified; db.SaveChanges(); return(Json(new { success = true, message = "Record & Stock Quantity Updated Successfully!" }, JsonRequestBehavior.AllowGet)); } return(View()); } }
public ActionResult AddStockOut(StockOut stkout) { using (EntitiesAPSCS db = new EntitiesAPSCS()) { var PartIDmatch = db.Items.Any(x => x.ItemPart.Equals(stkout.StockOutPart)); var GetItem = db.Items.FirstOrDefault(x => x.ItemPart == stkout.StockOutPart); if (stkout.StockOutID == 0) { if (!PartIDmatch) { return(Json(new { success = false, message = "Item Part Number Not Found!" }, JsonRequestBehavior.AllowGet)); } //else if (GetItem.ItemQuantity <= 10) //{ //} else if (stkout.StockOutQuantity > GetItem.ItemQuantity) { return(Json(new { success = false, message = "Not Enough Stock Quantity!" }, JsonRequestBehavior.AllowGet)); } else if (PartIDmatch == true && stkout.StockOutQuantity != null) { stkout.StockOutDescription = GetItem.ItemDescription; GetItem.ItemQuantity = GetItem.ItemQuantity - stkout.StockOutQuantity.Value; db.StockOuts.Add(stkout); db.SaveChanges(); return(Json(new { success = true, message = "Saved Successfully" }, JsonRequestBehavior.AllowGet)); } } } return(View()); }
public ActionResult ForgotPassword(string EmailID) { // setting request link string resetCode = Guid.NewGuid().ToString(); var verifyUrl = "/Home/ResetPassword/" + resetCode; var link = Request.Url.AbsoluteUri.Replace(Request.Url.PathAndQuery, verifyUrl); using (var context = new EntitiesAPSCS()) { var getUser = (from gu in context.Users where gu.Email == EmailID select gu).FirstOrDefault(); if (getUser != null) { getUser.ResetPasswordCode = resetCode; context.Configuration.ValidateOnSaveEnabled = false; context.SaveChanges(); // Emial content to reset password via link var subject = "Password Reset Request"; var body = "Hi " + getUser.Name + ", <br/><br/> Below please find the Password Reset Link requested from Auto Parts Stock Control System. Please click on the link to reset your password. " + " <br/><br/><a href='" + link + "'>" + link + "</a> <br/><br/>" + "If you no longor need to reset your password, Please ignore this message.<br/><br/> Thank you<br/><br/> Auto Parts Stock Control System"; SendEmail(getUser.Email, body, subject); ViewBag.Message1 = "Reset Link was sent to your Email Address."; } else { //Check if email exist ViewBag.Message = "Email Address does not exist!. Please check your input!"; return(View()); } } return(View()); }