public ActionResult UserEdit([Bind(Include = "UserID,UserName,Password,FirstName,LastName,Company,CompanyLogo,Email")] User user)
        {
            TakimOmruDBEntities db = new TakimOmruDBEntities();

            if (ModelState.IsValid)
            {
                if (Request.Files.Count > 0)
                {
                    //Guid nesnesini benzersiz dosya adı oluşturmak için tanımladık ve Replace ile aradaki “-” işaretini atıp yan yana yazma işlemi yaptık.
                    string DosyaAdi = Guid.NewGuid().ToString().Replace("-", "");
                    //Kaydetceğimiz resmin uzantısını aldık.
                    string uzanti     = System.IO.Path.GetExtension(Request.Files[0].FileName);
                    string TamYolYeri = "/Images/" + DosyaAdi + uzanti;
                    //Eklediğimiz Resni Server.MapPath methodu ile Dosya Adıyla birlikte kaydettik.
                    Request.Files[0].SaveAs(Server.MapPath(TamYolYeri));
                    //Ve veritabanına kayıt için dosya adımızı değişkene aktarıyoruz.
                    user.CompanyLogo = DosyaAdi + uzanti;
                }
                db.Entry(user).State = EntityState.Modified;
                db.SaveChanges();
                return(RedirectToAction("Profil", "Home"));
            }

            return(View(user));
        }
        //public ActionResult ParcaGuncelle(SubPiece subPiece, FormCollection form)
        //{
        //    var id = Convert.ToInt32(form["par"]);
        //    using (var ctx = new TakimOmruDBEntities())
        //    {
        //        var existingsubpiece = ctx.SubPiece.Where(s => s.SubPieceID == id)
        //                                                .FirstOrDefault();

        //        if (existingsubpiece != null)
        //        {
        //            existingsubpiece.SubPieceName = subPiece.SubPieceName;
        //            existingsubpiece.ToolLife = subPiece.ToolLife;

        //            ctx.SaveChanges();
        //        }
        //    }
        //    return RedirectToAction("TakimOmru", "Home");
        //}

        public ActionResult ParcaGuncelle(int ID)
        {
            TakimOmruDBEntities db   = new TakimOmruDBEntities();
            ThreeModel          test = new ThreeModel();

            test.subPiece = db.SubPiece.Find(ID);
            return(RedirectToAction("TakimOmru", "Home", test));
        }
        public ActionResult DeleteConfirmed(int id)
        {
            TakimOmruDBEntities db = new TakimOmruDBEntities();
            Note note = db.Notes.Find(id);

            db.Notes.Remove(note);
            db.SaveChanges();
            return(RedirectToAction("Note"));
        }
        public ActionResult DeletePiece(int?id)
        {
            TakimOmruDBEntities db = new TakimOmruDBEntities();
            Piece piece            = db.Piece.Find(id);

            db.Piece.Remove(piece);
            db.SaveChanges();
            return(RedirectToAction("Indexx"));
        }
예제 #5
0
        public ActionResult Export(FormCollection form)
        {
            TakimOmruDBEntities db = new TakimOmruDBEntities();
            var subpiece           = db.SubPiece.ToList();
            var detail             = db.Detail.ToList();
            var altkategori        = from s in subpiece
                                     join dt in detail on s.SubPieceID equals dt.FKSubPieceID
                                     where s.FKPieceID == Convert.ToInt32(form["idsubpiece"])
                                     select new
            {
                SubPieceId   = s.SubPieceID,
                SubPieceName = s.SubPieceName,
                ToolLife     = s.ToolLife,
                PieceId      = s.FKPieceID,
                PieceCount   = dt.PieceCount,
                CreatedDate  = dt.CreatedDate.Value.ToString("dd.MM.yyyy hh:mm")
            };
            var data = from obj in altkategori
                       select new
            {
                SubPieceId   = obj.SubPieceId,
                SubPieceName = obj.SubPieceName,
                ToolLife     = obj.ToolLife,
                PieceId      = obj.PieceId,
                PieceCount   = obj.PieceCount,
                CreatedDate  = obj.CreatedDate
            };

            Microsoft.Office.Interop.Excel.Application xla = new Microsoft.Office.Interop.Excel.Application();
            Workbook  wb = xla.Workbooks.Add(XlSheetType.xlWorksheet);
            Worksheet ws = (Worksheet)xla.ActiveSheet;

            xla.Visible = true;

            ws.Cells[1, 1] = "Parça Adı";
            ws.Cells[1, 2] = "Takım Ömrü";
            ws.Cells[1, 3] = "Parça Sayısı";
            ws.Cells[1, 4] = "Eklenme Tarihi";
            var i = 2;

            foreach (var item in data)
            {
                ws.Name        = item.PieceId.ToString();
                ws.Cells[i, 1] = item.SubPieceName;
                ws.Cells[i, 2] = item.ToolLife;
                ws.Cells[i, 3] = item.PieceCount;
                ws.Cells[i, 4] = item.CreatedDate;

                i++;
            }


            return(RedirectToAction("TakimOmru", "Home"));
        }
        public ActionResult ParcaSil(FormCollection form)
        {
            var id = Convert.ToInt32(form["parcaid"]);

            using (var ctx = new TakimOmruDBEntities())
            {
                SubPiece sub = ctx.SubPiece.Find(id);
                ctx.SubPiece.Remove(sub);
                ctx.SaveChanges();
            }
            return(RedirectToAction("TakimOmru", "Home"));
        }
예제 #7
0
        public ActionResult Upload(FormCollection formCollection)
        {
            var subpieceList = new List <Kapasitematik_TakimOmru_v3.SubPiece>();

            if (Request != null)
            {
                HttpPostedFileBase file = Request.Files["UploadedFile"];
                if ((file != null) && (file.ContentLength > 0) && !string.IsNullOrEmpty(file.FileName))
                {
                    string fileName        = file.FileName;
                    string fileContentType = file.ContentType;
                    byte[] fileBytes       = new byte[file.ContentLength];
                    var    data            = file.InputStream.Read(fileBytes, 0, Convert.ToInt32(file.ContentLength));
                    using (var package = new ExcelPackage(file.InputStream))
                    {
                        ExcelPackage.LicenseContext = LicenseContext.NonCommercial;
                        var currentSheet = package.Workbook.Worksheets;
                        var workSheet    = currentSheet.First();
                        var noOfCol      = workSheet.Dimension.End.Column;
                        var noOfRow      = workSheet.Dimension.End.Row;
                        for (int rowIterator = 1; rowIterator <= noOfRow; rowIterator++)
                        {
                            var subpiece = new Kapasitematik_TakimOmru_v3.SubPiece();

                            subpiece.SubPieceName = workSheet.Cells[rowIterator, 1].Value.ToString();

                            subpiece.ToolLife = Convert.ToInt32(workSheet.Cells[rowIterator, 2].Value);



                            subpieceList.Add(subpiece);
                        }
                    }
                }
            }
            using (TakimOmruDBEntities db = new TakimOmruDBEntities())
            {
                foreach (var item in subpieceList)
                {
                    db.SubPiece.Add(new SubPiece()
                    {
                        SubPieceName = item.SubPieceName,
                        ToolLife     = item.ToolLife,
                        FKPieceID    = Convert.ToInt32(formCollection["id"]),
                        Type         = Convert.ToBoolean("false")
                    });
                }
                db.SaveChanges();
            }
            return(RedirectToAction("TakimOmru", "Home"));
        }
        public ActionResult ParcaGuncelle(SubPiece subPiece, FormCollection form)
        {
            TakimOmruDBEntities db = new TakimOmruDBEntities();
            var id = Convert.ToInt32(form["par"]);
            var existingsubpiece = db.SubPiece.Where(s => s.SubPieceID == id).FirstOrDefault();

            if (existingsubpiece != null)
            {
                existingsubpiece.SubPieceName = subPiece.SubPieceName;
                existingsubpiece.ToolLife     = subPiece.ToolLife;
                db.SaveChanges();
            }
            return(RedirectToAction("TakimOmru", "Home"));
        }
        public ActionResult Create([Bind(Include = "SubPieceID,SubPieceName,ToolLife,Now,FKPieceID,FKUserID,Type")] SubPiece subPiece)
        {
            //ViewBag.Data = new SelectList(db.PimsunDeviceNoes, "DeviceNo", "MachineName", piece.FKDeviceID);
            TakimOmruDBEntities db = new TakimOmruDBEntities();

            if (ModelState.IsValid)
            {
                db.SubPiece.Add(subPiece);
                db.SaveChanges();
                return(RedirectToAction("TakimOmru", "Home"));
            }

            ViewBag.FKPieceID = new SelectList(db.Piece, "PieceID", "PieceName", subPiece.FKPieceID);
            ViewBag.FKUserID  = new SelectList(db.User, "UserID", "UserName", subPiece.FKUserID);
            return(RedirectToAction("TakimOmru", "Home"));
        }
        public ActionResult Profil()
        {
            if (Session["UserID"] == null)
            {
                return(RedirectToAction("Login", "Login"));
            }

            TakimOmruDBEntities db = new TakimOmruDBEntities();

            ViewBag.UserID  = Session["UserID"];
            ViewBag.Company = Session["Company"];
            ViewBag.Logo    = Session["Logo"];
            ViewBag.Name    = Session["FirstName"];
            int ID = Convert.ToInt32(Session["UserID"]);

            return(View(db.User.Where(x => x.UserID == ID).ToList()));
        }
        public ActionResult Edit([Bind(Include = "PieceID,PieceName,FKUserID,CreatedDate,Adet")] Piece piece)
        {
            ViewBag.UserID = Session["UserID"];
            int ID = Convert.ToInt32(Session["UserID"]);
            TakimOmruDBEntities db = new TakimOmruDBEntities();

            if (ModelState.IsValid)
            {
                piece.FKUserID        = ID;
                piece.Adet            = 0;
                piece.CreatedDate     = DateTime.Now;
                db.Entry(piece).State = EntityState.Modified;
                db.SaveChanges();
                return(RedirectToAction("Indexx"));
            }
            ViewBag.FKUserID = new SelectList(db.User, "UserID", "UserName", piece.FKUserID);
            return(View(piece));
        }
예제 #12
0
        public ActionResult AddUser(FormCollection form)
        {
            TakimOmruDBEntities db = new TakimOmruDBEntities();
            User user = new User();

            //eğer dosya gelmişse işlemleri yap
            if (Request.Files.Count > 0)
            {
                //Guid nesnesini benzersiz dosya adı oluşturmak için tanımladık ve Replace ile aradaki “-” işaretini atıp yan yana yazma işlemi yaptık.
                string DosyaAdi = Guid.NewGuid().ToString().Replace("-", "");
                //Kaydetceğimiz resmin uzantısını aldık.
                string uzanti     = System.IO.Path.GetExtension(Request.Files[0].FileName);
                string TamYolYeri = "/Images/" + DosyaAdi + uzanti;
                //Eklediğimiz Resni Server.MapPath methodu ile Dosya Adıyla birlikte kaydettik.
                Request.Files[0].SaveAs(Server.MapPath(TamYolYeri));
                //Ve veritabanına kayıt için dosya adımızı değişkene aktarıyoruz.
                user.CompanyLogo = DosyaAdi + uzanti;
            }

            user.Company   = form["company"];
            user.FirstName = form["firstname"];
            user.LastName  = form["lastname"];
            user.Email     = form["email"];
            user.UserName  = form["username"];
            //user.Password = hs.PassHass(form["password"]);
            user.Password = form["password"];
            db.User.Add(user);
            db.SaveChanges();
            return(Redirect("Login"));


            //using (var client = new HttpClient())
            //{
            //    client.BaseAddress = new Uri("https://1ns5809cw0.execute-api.eu-west-2.amazonaws.com/Prod/");
            //    client.DefaultRequestHeaders.Accept.Clear();
            //    client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
            //    HttpResponseMessage response = client.PostAsJsonAsync("api/Login/AddUser", user).Result;
            //    if (response.IsSuccessStatusCode)
            //    {
            //        return RedirectToAction("Login");
            //    }
            //    return null;
            //}
        }
        //Get
        public ActionResult Edit(int?id)
        {
            ViewBag.Name    = Session["FirstName"];
            ViewBag.Company = Session["Company"];
            ViewBag.Logo    = Session["Logo"];
            TakimOmruDBEntities db = new TakimOmruDBEntities();

            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Piece piece = db.Piece.Find(id);

            if (piece == null)
            {
                return(HttpNotFound());
            }
            return(View(piece));
        }
        public ActionResult ParcaEkle()
        {
            TakimOmruDBEntities db = new TakimOmruDBEntities();

            if (Session["UserID"] == null)
            {
                return(RedirectToAction("Login", "Login"));
            }
            var item = db.PimsunDeviceNoes.Select(x => new
            {
                x.DeviceNo,
                x.MachineName
            }).ToList();

            ViewBag.Data    = item;
            ViewBag.Name    = Session["FirstName"];
            ViewBag.Company = Session["Company"];
            ViewBag.Logo    = Session["Logo"];
            return(View());
        }
        //public ActionResult Notification(Notification notification)
        //{

        //    TakimOmruDBEntities db = new TakimOmruDBEntities();


        //    var altkategori = from s in db.SubPiece
        //                      join dt in db.Detail on s.SubPieceID equals dt.FKSubPieceID

        //                      select new
        //                      {
        //                          SubPieceId = s.SubPieceID,
        //                          SubPieceName = s.SubPieceName,
        //                          ToolLife = s.ToolLife,
        //                          PieceID = s.FKPieceID,
        //                          PieceCount = dt.PieceCount,
        //                          CreatedDate = dt.CreatedDate.Value.ToString("dd'/'MM'/'yyyy hh:mm")

        //                      };
        //    var data = altkategori.GroupBy(x => x.SubPieceId).Select(x => new
        //    {
        //        SubPieceId = x.First().SubPieceId,
        //        SubPieceName = x.First().SubPieceName,
        //        ToolLife = x.First().ToolLife,
        //        PieceID = x.First().PieceID,
        //        PieceCount = x.Sum(y => y.PieceCount),
        //        CreatedDate = x.First().CreatedDate
        //    }).Where(x => (x.PieceCount) > (x.ToolLife * 2) / 3);

        //    if (data != null)
        //    {
        //        db.Notification.Add(new Notification
        //        {
        //            Notification_Description = data.Select(x => x.SubPieceName) + "Parçasının ömrü tükenmek üzere",
        //            Notification_Date = DateTime.Now
        //        });
        //    }

        //    return Json(data);

        //}



        //public ActionResult Detay(int id)
        //{

        //    TakimOmruDBEntities db = new TakimOmruDBEntities();


        //    var altkategori = from s in db.SubPiece
        //                      join dt in db.Detail on s.SubPieceID equals dt.FKSubPieceID
        //                      where dt.FKSubPieceID==id
        //                      select new
        //                      {
        //                          SubPieceId = s.SubPieceID,
        //                          SubPieceName = s.SubPieceName,
        //                          PieceCount = dt.PieceCount,
        //                          CreatedDate = dt.CreatedDate

        //                      };
        //    return Json(
        //        new
        //        {
        //            data = from obj in altkategori
        //                   select new
        //                   {
        //                       SubPieceId = obj.SubPieceId,
        //                       SubPieceName = obj.SubPieceName,
        //                       PieceCount = obj.PieceCount,
        //                       CreatedDate = obj.CreatedDate
        //                   }
        //        }, JsonRequestBehavior.AllowGet);

        //}

        //public ActionResult AltKategoriTime()
        //{

        //    TakimOmruDBEntities db = new TakimOmruDBEntities();


        //    var altkategori = from s in db.SubPiece
        //                      join dt in db.Detail on s.SubPieceID equals dt.FKSubPieceID
        //                      where s.Type == true
        //                      select new
        //                      {
        //                          SubPieceId = s.SubPieceID,
        //                          SubPieceName = s.SubPieceName,
        //                          ToolLife = s.ToolLife,
        //                          PieceID = s.FKPieceID,
        //                          PieceCount = dt.PieceCount,
        //                          CreatedDate = dt.CreatedDate

        //                      };
        //    return Json(
        //        new
        //        {
        //            data = from obj in altkategori
        //                   select new
        //                   {
        //                       SubPieceId = obj.SubPieceId,
        //                       SubPieceName = obj.SubPieceName,
        //                       ToolLife = obj.ToolLife,
        //                       PieceID = obj.PieceID,
        //                       PieceCount = obj.PieceCount,
        //                       CreatedDate = obj.CreatedDate
        //                   }
        //        }, JsonRequestBehavior.AllowGet);

        //}
        //public ActionResult InsertPiece([FromBody]Piece piece)
        //{

        //    using (var client = new HttpClient())
        //    {
        //        client.BaseAddress = new Uri("https://x1mrph0du3.execute-api.eu-west-2.amazonaws.com/Prod/");
        //        client.DefaultRequestHeaders.Accept.Clear();
        //        client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
        //        HttpResponseMessage response = client.PostAsJsonAsync("api/prod/parcaekle", piece).Result;
        //        if (response.IsSuccessStatusCode)
        //        {
        //            return RedirectToAction("ParcaEkle");
        //        }
        //        return null;
        //    }
        //}
        public ActionResult Note()
        {
            if (Session["UserID"] == null)
            {
                return(RedirectToAction("Login", "Login"));
            }
            TakimOmruDBEntities db = new TakimOmruDBEntities();

            ViewBag.UserID = Session["UserID"];

            ViewBag.Company = Session["Company"];
            ViewBag.Logo    = Session["Logo"];
            ViewBag.Name    = Session["FirstName"];
            int         UserId = Convert.ToInt32(Session["UserID"]);
            ProfilModel pm     = new ProfilModel();

            pm.users = db.User.Where(x => x.UserID == UserId).ToList();
            pm.notes = db.Notes.ToList();
            return(View(pm));
        }
        public ActionResult Export()
        {
            TakimOmruDBEntities db = new TakimOmruDBEntities();
            var kategori           = db.Piece.ToList();

            Microsoft.Office.Interop.Excel.Application xla = new Microsoft.Office.Interop.Excel.Application();
            Workbook  wb = xla.Workbooks.Add(XlSheetType.xlWorksheet);
            Worksheet ws = (Worksheet)xla.ActiveSheet;

            ws.Name        = "Takımlar";
            xla.Visible    = true;
            ws.Cells[1, 1] = "Takım Adı";
            var i = 2;

            foreach (var item in kategori)
            {
                ws.Cells[i, 1] = item.PieceName;
                i++;
            }

            return(RedirectToAction("TakimOmru", "Home"));
        }
        //[HttpPost]
        //[ValidateAntiForgeryToken]
        //public ActionResult Edit([Bind(Include = "DetailID,PieceCount,CreatedDate,FKSubPieceID,FKUserID")] Detail detail)
        //{
        //    ViewBag.UserID = Session["UserID"];
        //    int ID = Convert.ToInt32(Session["UserID"]);
        //    if (ModelState.IsValid)
        //    {
        //        detail.FKUserID = ID;
        //        db.Entry(detail).State = EntityState.Modified;
        //        db.SaveChanges();
        //        return RedirectToAction("Index");
        //    }
        //    ViewBag.FKSubPieceID = new SelectList(db.SubPiece, "SubPieceID", "SubPieceName", detail.FKSubPieceID);
        //    ViewBag.FKUserID = new SelectList(db.User, "UserID", "UserName", detail.FKUserID);
        //    return View(detail);
        //}

        // GET: Piece/Delete/5
        public ActionResult Delete(int?id)
        {
            if (Session["UserID"] == null)
            {
                return(RedirectToAction("Login", "Login"));
            }
            ViewBag.Name    = Session["FirstName"];
            ViewBag.Company = Session["Company"];
            ViewBag.Logo    = Session["Logo"];
            TakimOmruDBEntities db = new TakimOmruDBEntities();

            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Piece piece = db.Piece.Find(id);

            if (piece == null)
            {
                return(HttpNotFound());
            }
            return(View(piece));
        }
        public ActionResult ParcaEklee(Piece piece)
        {
            var sessionId          = Convert.ToInt32(Session["UserID"]);
            TakimOmruDBEntities db = new TakimOmruDBEntities();

            ViewBag.Data = new SelectList(db.PimsunDeviceNoes, "DeviceNo", "MachineName", piece.FKDeviceID);
            try
            {
                db.Piece.Add(new Piece()
                {
                    PieceName   = piece.PieceName,
                    CreatedDate = piece.CreatedDate.GetValueOrDefault(DateTime.Now),
                    FKUserID    = sessionId,
                    FKDeviceID  = piece.FKDeviceID
                });
                db.SaveChanges();
                return(RedirectToAction("Indexx"));
            }
            catch (Exception)
            {
                return(RedirectToAction("ParcaEkle"));
            }
        }
예제 #19
0
        public ActionResult Token(User User)
        {
            if (ModelState.IsValid)
            {
                using (TakimOmruDBEntities db = new TakimOmruDBEntities())
                {
                    var obj = db.User.Where(a => a.UserName.Equals(User.UserName) && a.Password.Equals(User.Password)).FirstOrDefault();

                    if (obj != null)
                    {
                        if (User.Remember == true)
                        {
                            Response.Cookies["Username"].Value   = obj.UserName;
                            Response.Cookies["Password"].Value   = obj.Password;
                            Response.Cookies["Username"].Expires = DateTime.Now.AddDays(1);
                            Response.Cookies["Password"].Expires = DateTime.Now.AddDays(1);
                        }
                        else
                        {
                            Response.Cookies["Username"].Expires = DateTime.Now.AddDays(-1);
                            Response.Cookies["Password"].Expires = DateTime.Now.AddDays(-1);
                        }

                        Session.Add("UserID", obj.UserID.ToString());
                        Session.Add("Company", obj.Company.ToString());
                        Session.Add("Logo", obj.CompanyLogo.ToString());
                        Session.Add("FirstName", obj.FirstName.ToString() + " " + obj.LastName.ToString());

                        return(RedirectToAction("TakimOmru", "Home"));
                    }
                }
            }
            return(RedirectToAction("Login", "Login"));
            //TakimOmruDBEntities db = new TakimOmruDBEntities();

            //var u = db.User.Where(x => x.UserName == User.UserName && x.Password == hs.PassHass(User.Password));
            //if (u!=null)
            //{

            //    return RedirectToAction("TakimOmru", "Home");
            //}
            ////Session.Add("Company", u.Select(x=>x.Company));
            ////Session.Add("UserID", u.Select(x=>x.UserID));


            //return RedirectToAction("Login", "Login");

            //using (var client = new HttpClient())
            //{
            //    client.BaseAddress = new Uri("https://1ns5809cw0.execute-api.eu-west-2.amazonaws.com/Prod/");
            //    client.DefaultRequestHeaders.Accept.Clear();
            //    client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
            //    HttpResponseMessage response = client.PostAsJsonAsync("api/Login/Accesstoken",user).Result;
            //    if (response.IsSuccessStatusCode)
            //    {
            //        return RedirectToAction("TakimOmru","Home");
            //    }

            //    return View("Login");

            //}
        }
        public ActionResult TakimOmru(Notification noti, [Bind(Include = "NoteID,NoteHeader,NoteDescription,CreatedDate,FkPieceID,FkSubPieceID,FkUserID")] Note note)
        {
            //ActionResult result = null;
            TakimOmruDBEntities db = new TakimOmruDBEntities();

            ViewBag.FKPieceID = new SelectList(db.Piece, "PieceID", "PieceName");
            //ViewBag.FkSubPieceID = new SelectList(db.SubPiece, "SubPieceID", "SubPieceName");
            //ViewBag.FkUserID = new SelectList(db.User, "UserID", "UserName");

            if (Session["UserID"] == null)
            {
                return(RedirectToAction("Login", "Login"));
            }
            ViewBag.UserID  = Session["UserID"];
            ViewBag.Company = Session["Company"];
            ViewBag.Logo    = Session["Logo"];
            ViewBag.Name    = Session["FirstName"];
            int        UserId = Convert.ToInt32(Session["UserID"]);
            ThreeModel tm     = new ThreeModel();

            tm.notification = db.Notification.ToList();
            tm.pieces       = db.Piece.ToList();
            tm.subpieces    = db.SubPiece.ToList();
            tm.notes        = db.Notes.ToList();

            ViewBag.FkPieceIDd   = new SelectList(db.Piece, "PieceID", "PieceName", note.FkPieceID);
            ViewBag.FkSubPieceID = new SelectList(db.SubPiece, "SubPieceID", "SubPieceName", note.FkSubPieceID);
            ViewBag.FkUserID     = new SelectList(db.User, "UserID", "UserName", note.FkUserID);

            var altkategori = from s in db.SubPiece
                              join dt in db.Detail on s.SubPieceID equals dt.FKSubPieceID
                              where s.FKUserID == UserId
                              select new
            {
                SubPieceId   = s.SubPieceID,
                SubPieceName = s.SubPieceName,
                ToolLife     = s.ToolLife,
                PieceID      = s.FKPieceID,
                PieceCount   = dt.PieceCount,
            };
            var data = altkategori.GroupBy(x => x.SubPieceId).Select(x => new
            {
                SubPieceId   = x.FirstOrDefault().SubPieceId,
                SubPieceName = x.FirstOrDefault().SubPieceName,
                ToolLife     = x.FirstOrDefault().ToolLife,
                PieceID      = x.FirstOrDefault().PieceID,
                PieceCount   = x.Sum(y => y.PieceCount),
            }).Where(v => v.PieceCount > (v.ToolLife * 2) / 3);

            if (data != null && data.Any())
            {
                foreach (var item in data)
                {
                    db.Notification.Add(new Notification()
                    {
                        NotificationID           = noti.NotificationID,
                        Notification_Description = noti.Notification_Description = (item.SubPieceName) + " " + "parçasının ömrü tükenmek üzere Kalan parça sayısı " + (item.ToolLife - item.PieceCount),
                        Count             = noti.Count = 0,
                        FKUserId          = UserId,
                        Notification_Date = noti.Notification_Date.GetValueOrDefault(DateTime.Now),
                    });
                }

                db.SaveChanges();
            }

            //var noti = db.Notification.ToList();


            //ViewBag.PieceID = new SelectList(db.Piece, "PieceId", "PieceName", subPiece.FKPieceID);
            //ViewBag.Message = "Your application description page.";

            //ViewBag.Piece = new SelectList(db.Piece, "PieceId", "PieceName");
            //var prodecure= db.SP_Notification_Update_Counter_v1(UserId);
            return(View(tm));
        }