Ejemplo n.º 1
0
        public ActionResult Import( Object bla )
        {
            if ( Request.Files.Count > 0 ) {
                var file = Request.Files[ 0 ];
                string text;
                Pc pc = null;

                if ( file != null && file.ContentLength > 0 ) {
                    var fileName = Path.GetFileName( file.FileName );
                    var path = Path.Combine( Server.MapPath( "~/temp/" ), fileName );
                    file.SaveAs( path );

                    using ( StreamReader sr = new StreamReader( path ) ) {
                        text = sr.ReadToEnd();
                        sr.Close();
                    }

                    string[] splitt = text.Split( ',' );

                    if ( splitt.Length == 10 ) {

                        pc = new Pc() {
                            PcName = splitt[ 3 ],
                            UserName = splitt[ 5 ],
                            Windows = splitt[ 1 ],
                            WinRelese = splitt[ 6 ],
                            WinBuss = splitt[ 4 ],
                            SercvicePack = splitt[ 2 ],
                            Office = splitt[ 8 ],
                            OfficVersion = splitt[ 9 ]
                        };

                    } else if ( splitt.Length == 9 ) {
                        pc = new Pc() {
                            PcName = splitt[ 3 ],
                            UserName = splitt[ 4 ],
                            Windows = splitt[ 1 ],
                            WinRelese = splitt[ 5 ],
                            WinBuss = "32-Bit",
                            SercvicePack = splitt[ 2 ],
                            Office = splitt[ 7 ],
                            OfficVersion = splitt[ 8 ]
                        };
                    }

                    db.PcSet.Add( pc );
                    db.SaveChanges();
                    return RedirectToAction( "Edit", pc );
                } else
                    return RedirectToAction( "Index" );
            } else
                return RedirectToAction( "Index" );
        }
Ejemplo n.º 2
0
 public ActionResult Edit( Pc pc )
 {
     if ( ModelState.IsValid ) {
         if ( pc.Id == 0 ) {
             db.PcSet.Add( pc );
         } else {
             db.Entry( pc ).State = EntityState.Modified;
         }
         db.SaveChanges();
         return RedirectToAction( "Index" );
     }
     return View( pc );
 }