예제 #1
0
        public async Task <IActionResult> PutEmp(int id, Emp emp)
        {
            if (id != emp.empid)
            {
                return(BadRequest());
            }

            _context.Entry(emp).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!EmpExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
예제 #2
0
        public async Task <IHttpActionResult> PutEmp(int id, Emp emp)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != emp.Id)
            {
                return(BadRequest());
            }

            db.Entry(emp).State = EntityState.Modified;

            try
            {
                await db.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!EmpExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
 public async Task <IActionResult> AddEmployee(Employee emp)
 {
     try
     {
         if (ModelState.IsValid)
         {
             if (emp.ID == 0)
             {
                 _Db.tbl_Employee.Add(emp);
                 await _Db.SaveChangesAsync();
             }
             else
             {
                 _Db.Entry(emp).State = EntityState.Modified;
                 await _Db.SaveChangesAsync();
             }
             return(RedirectToAction("EmployeeList"));
         }
         return(View());
     }
     catch (Exception e)
     {
         return(RedirectToAction("EmployeeList"));
     }
 }
예제 #4
0
파일: Emp.cs 프로젝트: kaveshy/sequel
        public async Task <string> Post([FromBody] EmpDetails value)
        {
            await _db.Entries.AddAsync(value);

            await _db.SaveChangesAsync();

            return(value.EmployeeId + " - " + value.Name + " : " + value.Surname);
        }
예제 #5
0
        public async Task <ActionResult <Employee> > CreateEmp(Employee emp)
        {
            emp.DateOfJoining = DateTime.Now;
            emp.IsActive      = true;
            _context.EmpCollection.Add(emp);
            await _context.SaveChangesAsync();

            return(CreatedAtAction(nameof(GetEmployee), new { id = emp.Id }, emp));
        }
예제 #6
0
        public async Task <IActionResult> Create([Bind("ID,LastName,FirstName,StartingDate")] Supervisor supervisor)
        {
            if (ModelState.IsValid)
            {
                _context.Add(supervisor);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(supervisor));
        }
        public async Task <IActionResult> Create([Bind("EId,EName,EDesig,EDOJ")] Emp emp)
        {
            if (ModelState.IsValid)
            {
                _context.Add(emp);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(emp));
        }
예제 #8
0
        public async Task <IActionResult> Create([Bind("DepartmentID,Title,Budget")] Department department)
        {
            if (ModelState.IsValid)
            {
                _context.Add(department);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(department));
        }
예제 #9
0
        public async Task <IActionResult> Create([Bind("ContractID,DepartmentID,StandardID,SupervisorID")] Contract contract)
        {
            if (ModelState.IsValid)
            {
                _context.Add(contract);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["DepartmentID"] = new SelectList(_context.Departments, "DepartmentID", "Title", contract.DepartmentID);
            ViewData["StandardID"]   = new SelectList(_context.Standards, "ID", "FirstName", contract.StandardID);
            ViewData["SupervisorID"] = new SelectList(_context.Supervisors, "ID", "FirstName", contract.SupervisorID);
            return(View(contract));
        }
        public async Task <int> InsertDepartment(Department d)
        {
            context.Department.Add(d);
            await context.SaveChangesAsync();

            return(d.Id);
        }
        public async Task <int> InsertEmployee(Employee e)
        {
            VMDepartmentQuery query = new VMDepartmentQuery(context);
            await ss.WaitAsync();

            try
            {
                const int nrMaxEmp = 5;
                int       nrEmps   = await query.NumberEmployees(e.Iddepartment);

                if (nrEmps >= nrMaxEmp)
                {
                    throw new NotSupportedException("department have more that ${nrMaxEmp} employees");
                }

                context.Employee.Add(e);
                return(await context.SaveChangesAsync());
            }
            finally
            {
                ss.Release();
            }
        }