示例#1
0
        public string Create(MaterialModel materialEntity)
        {
            try
            {
                using (System.Data.SqlClient.SqlConnection sqlConnection = new System.Data.SqlClient.SqlConnection(Connectionstring))
                {
                    sqlConnection.Open();

                    string sqlQuery = "INSERT INTO Material(_MaterialType_key,MaterialID,MaterialName,_Workgroup_key,CreatedBy,DateCreated,ModifiedBy,DateModified) VALUES (@_MaterialType_key,@MaterialID,@MaterialName,@_Workgroup_key,@CreatedBy,@DateCreated,@ModifiedBy,@DateModified)";
                    sqlConnection.Execute(sqlQuery,
                                          new
                                          {
                                              materialEntity._MaterialType_key,
                                              materialEntity.MaterialID,
                                              materialEntity.MaterialName,
                                              materialEntity._Workgroup_key,
                                              materialEntity.CreatedBy,
                                              materialEntity.DateCreated,
                                              materialEntity.ModifiedBy,
                                              materialEntity.DateModified
                                          });

                    sqlConnection.Close();

                }
                return "Created";
            }
            catch (Exception ex)
            {
                return ex.Message;
            }
        }
 public ActionResult Edit(MaterialModel material)
 {
     try
     {
         // TODO: Add update logic here
         var materialDB = new MaterialDB();
         materialDB.Update(material);
         return RedirectToAction("Index");
     }
     catch
     {
         return View();
     }
 }
 public ActionResult Create(MaterialModel material)
 {
     try
     {
         var materialDB = new MaterialDB();
         var cvDB=new CvDB();
         material.MaterialTypeSelectList = new SelectList(cvDB.GetMaterialTypes(),"_MaterialType_key", "MaterialType");
         materialDB.Create(material);
         return RedirectToAction("Index");
     }
     catch
     {
         return View();
     }
 }
示例#4
0
        public bool Update(MaterialModel animalEntity)
        {
            try
            {
                using (System.Data.SqlClient.SqlConnection sqlConnection = new System.Data.SqlClient.SqlConnection(Connectionstring))
                {
                    sqlConnection.Open();
                    string sqlQuery = "UPDATE Material SET _MaterialType_key=@_MaterialType_key,MaterialID=@MaterialID,MaterialName=@MaterialName WHERE _Material_key=@_Material_key";
                    sqlConnection.Execute(sqlQuery, new
                    {
                        animalEntity._MaterialType_key,
                        animalEntity.MaterialID,
                        animalEntity.MaterialName,
                        animalEntity._Material_key
                    });
                    sqlConnection.Close();

                }
                return true;
            }
            catch (Exception exception)
            {
                return false;
            }
        }