Exemplo n.º 1
0
        public HttpResponseMessage AddEmployee(Employee employee)
        {
            empContext.Employees.Add(employee);
            empContext.SaveChanges();

            return(Request.CreateResponse(HttpStatusCode.OK, employee, System.Net.Http.Formatting.JsonMediaTypeFormatter.DefaultMediaType));
        }
Exemplo n.º 2
0
        public ActionResult Create(Employee employee)
        {
            //Thread.Sleep(2000);
            db.Employee.Add(employee);
            db.SaveChanges();

            return(Json(employee, JsonRequestBehavior.AllowGet));
        }
Exemplo n.º 3
0
        public JsonResult Create(Department department)
        {
            // Thread.Sleep(2000);
            db.Department.Add(department);
            db.SaveChanges();

            return(Json(department, JsonRequestBehavior.AllowGet));
        }
Exemplo n.º 4
0
 public ActionResult Add(Department dep)
 {
     if (ModelState.IsValid)
     {
         _context.Departments.Add(dep);
         _context.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View());
 }
Exemplo n.º 5
0
        public ActionResult Create(Employee1 emp)
        {
            if (ModelState.IsValid)
            {
                db.Emp1.Add(emp);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(emp));
        }
Exemplo n.º 6
0
        public ActionResult Create([Bind(Include = "EmpId,Ename,Edesig,Edoj")] Emp emp)
        {
            if (ModelState.IsValid)
            {
                db.Emps.Add(emp);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(emp));
        }
Exemplo n.º 7
0
        public ActionResult Create([Bind(Include = "EId,EName,Email,Phone,MaritalStatus,State,City")] Employee1 emp)
        {
            if (ModelState.IsValid)
            {
                db.Emp1.Add(emp);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(emp));
        }
 public bool AddEmployee(EmployeeModel addEmployee)
 {
     try
     {
         emp.employeeModels.Add(addEmployee);
         emp.SaveChanges();
         return(true);
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Exemplo n.º 9
0
        //  public MemberDto CreateMember(MemberDto memberDto)
        public IHttpActionResult CreateMember(EmpDto empdto)
        {
            if (!ModelState.IsValid)
            {
                // throw new HttpResponseException(HttpStatusCode.BadRequest);
                return(BadRequest());
            }
            var emp = Mapper.Map <EmpDto, Emp>(empdto);

            db.Emps.Add(emp);
            db.SaveChanges();
            empdto.Id = emp.Id;
            return(Created(new Uri(Request.RequestUri + "/" + emp.Id), empdto));
            //      return memberDto();
        }
Exemplo n.º 10
0
 public ActionResult Index(Models.Employee e1, FormCollection f)
 {
     e1.Dno = Convert.ToInt32(f["dept"]);
     obj.Emps.Add(e1);
     obj.SaveChanges();
     return(RedirectToAction("Index", "Employee"));
 }
        public ActionResult Index(Models.Dept e1, string b1)
        {
            if (b1 == "Save")
            {
                obj.Depts.Add(e1);
                obj.SaveChanges();
            }
            else if (b1 == "Update")
            {
                Dept d = obj.Depts.Find(e1.Dno);
                d.Dname = e1.Dname;
                obj.SaveChanges();
            }

            return(RedirectToAction("Index"));
        }
Exemplo n.º 12
0
 public ActionResult Create(EmployeeVM person)
 {
     if (ModelState.IsValid)
     {
         context.Emps.Add(person.Employee);
         context.SaveChanges();
     }
     return(RedirectToAction("Index"));
 }
Exemplo n.º 13
0
        public ActionResult Add(Employee Employee)
        {
            var employeeVm = new EmployeeViewModel()
            {
                Departments = _context.Departments.ToList()   // i need to initialize my Departments with the Departments from the DB
            };

            if (ModelState.IsValid)
            {
                _context.Employees.Add(Employee);
                _context.SaveChanges();
                return(RedirectToAction("Index"));      // return the redirected view of the Index  (table after adding)
            }



            return(View(employeeVm));
        }
Exemplo n.º 14
0
        public EmpController(EmpContext context)
        {
            _context = context;

            if (_context.EmpCollection.Count() == 0)
            {
                _context.EmpCollection.Add(new Employee {
                    FirstName = "John", LastName = "Doe", DateOfJoining = System.DateTime.Now, Manager = "Tom", IsActive = true
                });
                _context.SaveChanges();
            }
        }
Exemplo n.º 15
0
        public virtual TObject Create(TObject tobject)
        {
            var name = tobject.GetType().Name;

            if (name == "Building" || name == "Meter" || name == "Organization")
            {
                VO.Common.MeterCache.Init();
            }
            if (name == "User" || name == "Building" || name == "Organization")
            {
                VO.Common.UserCache.Init();
            }
            var newEntry = DbSet.Add(tobject);

            try
            {
                if (!shareContext)
                {
                    db.SaveChanges();
                }
            }
            catch (System.Data.Entity.Validation.DbEntityValidationException dbEx)
            {
                MyConsole.Log(dbEx);
                throw dbEx;
            }
            catch (Exception dbEx)
            {
                MyConsole.Log(dbEx);
                throw dbEx;
            }
            return(newEntry);
        }
Exemplo n.º 16
0
        public IHttpActionResult PostRelationship(CategoryDictionary category, RelationshipModel <int, int> rels)
        {
            EmpContext content1 = new EmpContext();
            var        list     = brandBLL.Filter(x => rels.PKS.Contains(x.Id)).ToList();

            if (list.Count != rels.PKS.Count)
            {
                return(BadRequest("参数出错,部分品牌信息未找到,请审查后再提交"));
            }
            switch (category)
            {
            case CategoryDictionary.Meter:
                if (list.Count != 1)
                {
                    return(BadRequest("参数出错,品牌参数只能一条,请审查后再提交"));
                }
                var brand  = list.FirstOrDefault();
                var meters = meterBLL.Filter(x => rels.FKS.Contains(x.Id)).ToList();
                if (meters.Count != rels.FKS.Count)
                {
                    return(BadRequest("参数出错,部分参数信息未找到,请审查后再提交"));
                }
                var obj = new JObject();
                obj.Add("BrandId", brand.Id);
                meterBLL.Update(x => rels.FKS.Contains(x.Id), obj);
                //meterBLL.Update(x => rels.FKS.Contains(x.Id), new { BrandID = brand.Id });
                break;

            case CategoryDictionary.Parameter:
                //var parameters = paramBLL.Filter(x => rels.FKS.Contains(x.Id)).ToList();
                var dicts = dictBLL.Filter(x => x.Code == "Parameter" && rels.FKS.Contains(x.Id)).ToList();
                if (dicts.Count != rels.FKS.Count)
                {
                    return(BadRequest("参数出错,部分参数信息未找到,请审查后再提交"));
                }
                foreach (var brandId in list)
                {
                    foreach (var param in rels.FKS)
                    {
                        Parameter parameters = new Parameter();
                        parameters.BrandId = brandId.Id;
                        parameters.TypeId  = param;
                        parameters.Unit    = dicts.Where(x => x.Id == param).FirstOrDefault().EquText;
                        content1.Parameters.Add(parameters);
                    }
                }
                content1.SaveChanges();
                content1.Dispose();
                //return BadRequest("系统暂不支持此功能");
                break;

            case CategoryDictionary.Building:
            case CategoryDictionary.BuidlingCategory:
            case CategoryDictionary.MeterType:
            case CategoryDictionary.Brand:
            case CategoryDictionary.Organization:
            case CategoryDictionary.Manager:
            case CategoryDictionary.Role:
            case CategoryDictionary.Permission:
            default:
                return(BadRequest("系统不支持此功能"));

                break;
            }
            return(Ok());
        }
Exemplo n.º 17
0
        public ActionResult Create([Bind(Include = "EmployeeID,FirstName,LastName,Reference,ManualRefrence")] Employee employee)
        {
            //initialization

            // take the reference request
            string ReferenceBuff = "";

            try
            {
                ReferenceBuff = Request["Reference"].ToString();
            }
            catch (NullReferenceException)
            {
                ReferenceBuff = "";
            }
            //initialize employee instance to null
            Employee empRef = null;
            //initialize the current date to use current year
            DateTime date = DateTime.Now;

            //initialize string for manual reference
            string ManualRef = "";

            if (ReferenceBuff == "")
            {
                empRef = null;
            }
            else
            {
                try
                {
                    empRef = db.Employees.First(x => x.Reference == ReferenceBuff);
                }
                catch (InvalidOperationException)
                {
                    empRef = null;
                }

                if (empRef != null)
                {
                    return(RedirectToAction("ErrorPage"));
                }
                else
                {
                    ManualRef = "FSR-WL/" + ReferenceBuff + "/" + date.Year;
                }
            }

            if (ModelState.IsValid)
            {
                try
                {
                    db.Employees.Add(employee);
                    db.SaveChanges();
                    if (ReferenceBuff == "")
                    {
                        var refer = addRef(employee);
                        employee.Reference = refer;
                    }
                    else
                    {
                        employee.Reference = ManualRef;
                    }
                    db.SaveChanges();
                }
                catch (DbUpdateException)
                {
                    db.Entry(employee).State = EntityState.Deleted;
                    db.SaveChanges();
                    return(RedirectToAction("ErrorPage"));
                }

                return(RedirectToAction("Index"));
            }


            //db.SaveChanges();
            return(View(employee));
        }
Exemplo n.º 18
0
 public void SaveRecord()
 {
     db.SaveChanges();
 }
Exemplo n.º 19
0
 public int Complete()
 {
     return(cc.SaveChanges());
 }