Example #1
0
        public ActionResult Create(Material material)
        {
            if (ModelState.IsValid)
            {
                db.Materials.Add(material);
                db.SaveChanges();
                return RedirectToAction("Index");
            }

            ViewBag.LocationID = new SelectList(db.Locations, "LocationID", "Description", material.LocationID);
            ViewBag.CorporateAccountID = new SelectList(db.CorporateAccounts, "CorporateAccountID", "Title", material.CorporateAccountID);
            ViewBag.ParentMaterialID = new SelectList(db.Materials, "MaterialID", "Description", material.ParentMaterialID);
            ViewBag.MaterialCategoryID = new SelectList(db.MaterialCategories, "MaterialCategoryID", "Description", material.MaterialCategoryID);
            ViewBag.MaterialGroupID = new SelectList(db.MaterialGroups, "MaterialGroupID", "Description", material.MaterialGroupID);
            ViewBag.MaterialTypeID = new SelectList(db.MaterialTypes, "MaterialTypeID", "Description", material.MaterialTypeID);
            ViewBag.ValidationStateID = new SelectList(db.ValidationStates, "ValidationStateID", "Description", material.ValidationStateID);
            return View(material);
        }
Example #2
0
        public ActionResult Edit(Material material, IEnumerable<HttpPostedFileBase> files, FormCollection formcollection)
        {
            if (ModelState.IsValid)
            {
                Material secilenMaterial = db.Materials.SingleOrDefault(s => s.MaterialID == material.MaterialID);
                secilenMaterial.Description = material.Description;
                secilenMaterial.ComponentModel = material.ComponentModel;
                secilenMaterial.CorporateAccount = material.CorporateAccount;
                secilenMaterial.CorporateAccountID = material.CorporateAccountID;
                secilenMaterial.Location = secilenMaterial.Location;
                secilenMaterial.LocationID = material.LocationID;
                secilenMaterial.MaterialCategory = material.MaterialCategory;
                secilenMaterial.MaterialCategoryID = secilenMaterial.MaterialCategoryID;
                secilenMaterial.MaterialCodeNum = material.MaterialCodeNum;
                secilenMaterial.MaterialFiles = material.MaterialFiles;
                secilenMaterial.MaterialGroup = material.MaterialGroup;
                secilenMaterial.MaterialGroupID = material.MaterialGroupID;
                secilenMaterial.MaterialType = material.MaterialType;
                secilenMaterial.MaterialTypeID = material.MaterialTypeID;
                secilenMaterial.Note = material.Note;
                secilenMaterial.ParentMaterial = material.ParentMaterial;
                secilenMaterial.ParentMaterialID = material.ParentMaterialID;
                secilenMaterial.RackLocation = material.RackLocation;
                secilenMaterial.ValidationState = material.ValidationState;
                secilenMaterial.ValidationStateID = material.ValidationStateID;

                //db.SaveChanges();

                #region MaterialKlasorleriniKaydet

                if (files != null)
                {
                    foreach (var file in files)
                    {
                        if (file != null)
                        {
                            string filename = null;
                            string fileType = null;
                            byte[] fileContents = null;

                            fileContents = new byte[file.ContentLength];
                            file.InputStream.Read(fileContents, 0, file.ContentLength);
                            fileType = file.ContentType;
                            filename = file.FileName;

                            MaterialFile materialFile = new MaterialFile();
                            materialFile.MaterialFileName = filename;
                            materialFile.MaterialFileContentType = fileType;
                            materialFile.MaterialFileSize = fileContents != null ? fileContents.Length : 0;
                            materialFile.MaterialFileContents = fileContents;
                            materialFile.MaterialID = material.MaterialID;
                            materialFile.MaterialFileDescription = formcollection["EklenenDosyaAciklama"].ToString();

                            db.MaterialFiles.Add(materialFile);

                            //MaterialFile materialFile = new MaterialFile();
                            //materialFile.MaterialFileName = file.FileName;
                            //materialFile.MaterialFileContentType = file.ContentType;
                            //materialFile.MaterialFileSize = file.ContentLength;
                            //materialFile.MaterialFileContents = new byte[file.ContentLength];
                            //file.InputStream.Read(materialFile.MaterialFileContents, 0, materialFile.MaterialFileSize);
                            //materialFile.MaterialID = material.MaterialID;
                            //db.MaterialFiles.Add(materialFile);
                            //db.SaveChanges();
                        }
                    }
                }

                #endregion

                //db.Entry(material).State = EntityState.Modified;
                db.SaveChanges();
                string materialCategoryID = material.MaterialCategoryID.ToString();
                return RedirectToAction("Index", new { ID=materialCategoryID });

            }

            ViewBag.LocationID = new SelectList(db.Locations, "LocationID", "Description", material.LocationID);
            ViewBag.CorporateAccountID = new SelectList(db.CorporateAccounts, "CorporateAccountID", "Title", material.CorporateAccountID);
            ViewBag.ParentMaterialID = new SelectList(db.Materials, "MaterialID", "Description", material.ParentMaterialID);
            ViewBag.MaterialCategoryID = new SelectList(db.MaterialCategories, "MaterialCategoryID", "Description", material.MaterialCategoryID);
            ViewBag.MaterialGroupID = new SelectList(db.MaterialGroups, "MaterialGroupID", "Description", material.MaterialGroupID);
            ViewBag.MaterialTypeID = new SelectList(db.MaterialTypes, "MaterialTypeID", "Description", material.MaterialTypeID);
            ViewBag.ValidationStateID = new SelectList(db.ValidationStates, "ValidationStateID", "Description", material.ValidationStateID);
            return View(material);
        }