コード例 #1
0
        public long AddOrUpdateDepartment(AddDepartmentCriteria departmentCirteria)
        {
            long       retour     = 0;
            Department department = departmentCirteria.department;

            if (department != null)
            {
                Department departmentToUpdateOrSave = null;
                departmentToUpdateOrSave = (department.Id != 0) ? db.Departments.Find(department.Id) : db.Departments.Create();
                departmentToUpdateOrSave.department_name = department.department_name;
                departmentToUpdateOrSave.isWorkshop      = department.isWorkshop;
                db.Entry(departmentToUpdateOrSave).State = (department.Id != 0) ? EntityState.Modified : EntityState.Added;

                List <long> altelierIds = departmentCirteria.altelierIds;
                if (altelierIds.Count() > 0)
                {
                    //Add into table derpatment_altelier
                }

                db.SaveChanges();
                retour = departmentToUpdateOrSave.Id;
            }

            return(retour);
        }
コード例 #2
0
        public int ModifyUser(long id, string username, string password, int authority)
        {
            int retour = 0;

            using (var db = new ManagementDbContext())
            {
                try
                {
                    var result = (from u in db.Users
                                  where u.Username == username && u.Id != id
                                  select u.Id).FirstOrDefault();

                    if (result == 0)
                    {
                        var user = db.Users.Find(id);
                        user.Username        = username;
                        user.Password        = password;
                        user.Authority       = authority;
                        user.UpdateBy        = Comon.UserId;
                        db.Entry(user).State = EntityState.Modified;
                        //db.SaveChanges();
                        db.SaveChanges();
                        retour = 1;
                    }
                }
                catch (Exception e)
                {
                    retour = 0;
                }
            }
            return(retour);
        }
コード例 #3
0
        public long AddOrUpdateAltelier(Altelier altelier)
        {
            long retour = 0;

            if (altelier != null)
            {
                Altelier altelierToUpdateOrSave = null;
                altelierToUpdateOrSave = (altelier.Id > 0) ? db.Alteliers.Find(altelier.Id) : db.Alteliers.Create();
                altelierToUpdateOrSave.alterlier_name      = altelier.alterlier_name;
                altelierToUpdateOrSave.alterlier_propotion = altelier.alterlier_propotion;


                db.Entry(altelierToUpdateOrSave).State = (altelier.Id > 0) ? EntityState.Modified : EntityState.Added;

                db.SaveChanges();// TODO: change to asyn
                retour = altelierToUpdateOrSave.Id;
            }

            return(retour);
        }
コード例 #4
0
        public long AddorUpdateEmployee(Employee employee)
        {
            long retour = 0;

            if (employee != null)
            {
                Employee employeeToSaveOrUpdate = null;
                employeeToSaveOrUpdate = (employee.id > 0) ? db.Employees.Find(employee.id) : db.Employees.Create();
                employeeToSaveOrUpdate.employee_name         = employee.employee_name;
                employeeToSaveOrUpdate.altelier_id           = employee.altelier_id;
                employeeToSaveOrUpdate.haveDorm              = employee.haveDorm;
                employeeToSaveOrUpdate.haveSeniorityPay      = employee.haveSeniorityPay;
                employeeToSaveOrUpdate.havePaySocialSecurity = employee.havePaySocialSecurity;
                employeeToSaveOrUpdate.isTeamLeader          = employee.isTeamLeader;
                db.Entry(employeeToSaveOrUpdate).State       = (employee.id > 0) ? EntityState.Modified : EntityState.Added;

                db.SaveChanges();
                retour = employeeToSaveOrUpdate.id;
            }


            return(retour);
        }
コード例 #5
0
        public long AddOrUpdateUser(User user)
        {
            long retour = 0;

            if (user != null)
            {
                User userToCreateOrUpdate = null;

                userToCreateOrUpdate = (user.Id > 0) ? db.Users.Find(user.Id) : db.Users.Create();
                if (db.Users.Where(p => p.Username == user.Username).FirstOrDefault() != null && user.Id == 0)
                {
                    return(0);
                }
                userToCreateOrUpdate.Username  = user.Username;
                userToCreateOrUpdate.Password  = Comon.GetEncryptText(user.Password);
                userToCreateOrUpdate.Authority = user.Authority;

                db.Entry(userToCreateOrUpdate).State = (user.Id > 0) ? EntityState.Modified : EntityState.Added;
                db.SaveChanges();//TODO: async
                retour = userToCreateOrUpdate.Id;
            }

            return(retour);
        }
コード例 #6
0
        public long AddOrUpdateRevenue(Revenue revenue)
        {
            long retour = 0;

            if (revenue != null)
            {
                Revenue revenueToCreateOrUpdate = null;

                revenueToCreateOrUpdate = (revenue.id > 0) ? db.Revenues.Find(revenue.id) : db.Revenues.Create();
                if (db.Revenues.Where(p => p.year == revenue.year && p.month == revenue.month).FirstOrDefault() != null && revenue.id == 0)
                {
                    return(0);
                }
                revenueToCreateOrUpdate.year   = revenue.year;
                revenueToCreateOrUpdate.month  = revenue.month;
                revenueToCreateOrUpdate.number = revenue.number;

                db.Entry(revenueToCreateOrUpdate).State = (revenue.id > 0) ? EntityState.Modified : EntityState.Added;
                db.SaveChanges();//TODO: async
                retour = revenueToCreateOrUpdate.id;
            }

            return(retour);
        }
コード例 #7
0
 public virtual void Update(T entity)
 {
     dbSet.Attach(entity);
     dataContext.Entry(entity).State = EntityState.Modified;
 }