Ejemplo n.º 1
0
 public async Task <IActionResult> Update([FromBody] MyFirstTables model)
 {
     try
     {
         db.Entry(model).State = Microsoft.EntityFrameworkCore.EntityState.Modified;
         db.SaveChanges();
         return(Ok("Success"));
     }
     catch (Exception ex)
     {
         return(BadRequest(ex));
     }
 }
Ejemplo n.º 2
0
 public async Task <IActionResult> Create([FromBody] MyFirstTables model)
 {
     try
     {
         db.MyFirstTables.Add(model);
         db.SaveChanges();
         return(Ok("Success"));
     }
     catch (Exception ex)
     {
         return(BadRequest(ex));
     }
 }
Ejemplo n.º 3
0
        public async Task <IActionResult> OnGetAsync(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            MyFirstTables = await _context.MyFirstTables.FirstOrDefaultAsync(m => m.Id == id);

            if (MyFirstTables == null)
            {
                return(NotFound());
            }
            return(Page());
        }
Ejemplo n.º 4
0
        public async Task <IActionResult> OnPostAsync(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            MyFirstTables = await _context.MyFirstTables.FindAsync(id);

            if (MyFirstTables != null)
            {
                _context.MyFirstTables.Remove(MyFirstTables);
                await _context.SaveChangesAsync();
            }

            return(RedirectToPage("./Index"));
        }
Ejemplo n.º 5
0
 public async Task <IActionResult> AddEditEmployee(EmployeeViewModel model)
 {
     try
     {
         if (ModelState.IsValid)
         {
             MyFirstTables emp   = new MyFirstTables();
             bool          IsNew = model.Id != 0 ? false : true;
             if (!IsNew)
             {
                 emp = await db.MyFirstTables.SingleOrDefaultAsync(a => a.Id == model.Id);
             }
             emp.Name = model.Name;
             emp.Age  = model.Age;
             var path = "";
             if (model.Profile.FileName != null)
             {
                 path = Path.Combine(
                     Directory.GetCurrentDirectory(), "wwwroot\\ProfilePicture", model.Profile.FileName);
                 using (var stream = new FileStream(path, FileMode.Create))
                 {
                     await model.Profile.CopyToAsync(stream);
                 }
             }
             emp.Profile      = model.Profile.FileName != null ? path : emp.Profile;
             emp.LastModified = model.LastModified;
             emp.Country      = model.Country;
             if (IsNew)
             {
                 await db.MyFirstTables.AddAsync(emp);
             }
             await db.SaveChangesAsync();
         }
     }
     catch (Exception ex)
     {
         //return NotFound(ex);
     }
     return(RedirectToAction("Index"));
 }