Ejemplo n.º 1
0
        public SaveResult EditUserWtithRoles(UserResult entity)
        {
            return(ExecuteDbWithHandle(_logService, () =>
            {
                var result = SaveResult.FAILURE;

                using (var context = new TechOfficeEntities())
                {
                    using (var transaction = context.BeginTransaction())
                    {
                        var update = context.Users.Where(x => x.Id == entity.Id).Single();

                        update.UserName = entity.UserName;
                        update.IsLocked = entity.IsLocked;
                        update.HoVaTen = entity.HoVaTen;
                        update.ChucVuId = entity.ChucVuId;
                        update.CoQuanId = entity.CoQuanId;

                        update.IsDeleted = entity.IsDeleted;
                        update.LastUpdatedBy = entity.LastUpdatedBy;
                        update.LastUpdated = DateTime.Now;

                        context.Entry(update).State = EntityState.Modified;

                        //Remove all roles of user
                        RemoveAllRolesOfUser(context, entity.Id);

                        UserRole role;
                        foreach (var item in entity.UserRoles)
                        {
                            role = context.UserRoles.Create();
                            role.RoleId = item.RoleInfo.Id;
                            role.UserId = update.Id;

                            role.IsDeleted = entity.IsDeleted;
                            role.CreatedBy = update.CreatedBy;
                            role.CreateDate = update.CreateDate;

                            context.Entry(role).State = EntityState.Added;
                        }

                        result = context.SaveChanges() > 0 ? SaveResult.SUCCESS : SaveResult.FAILURE;

                        transaction.Commit();
                    }
                }
                return result;
            }));
        }
Ejemplo n.º 2
0
        public SaveResult AddUserWithRoles(UserResult entity)
        {
            return(ExecuteDbWithHandle(_logService, () =>
            {
                var result = SaveResult.FAILURE;

                using (var context = new TechOfficeEntities())
                {
                    using (var transaction = context.BeginTransaction())
                    {
                        var add = context.Users.Create();

                        add.UserName = entity.UserName;
                        add.Password = AppCipher.EncryptCipher(entity.Password);
                        add.IsLocked = entity.IsLocked;
                        add.HoVaTen = entity.HoVaTen;
                        add.ChucVuId = entity.ChucVuId;
                        add.CoQuanId = entity.CoQuanId;

                        add.IsDeleted = entity.IsDeleted;
                        add.CreatedBy = entity.CreatedBy;
                        add.CreateDate = DateTime.Now;

                        context.Entry(add).State = EntityState.Added;

                        UserRole role;
                        foreach (var item in entity.UserRoles)
                        {
                            role = context.UserRoles.Create();

                            role.RoleId = item.RoleInfo.Id;
                            role.UserId = add.Id;

                            role.IsDeleted = entity.IsDeleted;
                            role.CreatedBy = add.CreatedBy;
                            role.CreateDate = add.CreateDate;

                            context.Entry(role).State = EntityState.Added;
                        }

                        result = context.SaveChanges() > 0 ? SaveResult.SUCCESS : SaveResult.FAILURE;

                        transaction.Commit();
                    }
                }
                return result;
            }));
        }
Ejemplo n.º 3
0
        public async Task <SaveResult> AddAsync(ThuTucResult entity)
        {
            return(await ExecuteDbWithHandleAsync(_logService, async() =>
            {
                using (var context = new TechOfficeEntities())
                {
                    using (var transaction = context.BeginTransaction())
                    {
                        entity.AddToDb(context);
                        var result = await context.SaveChangesAsync() > 0 ? SaveResult.SUCCESS : SaveResult.FAILURE;

                        transaction.Commit();

                        return result;
                    }
                }
            }));
        }
Ejemplo n.º 4
0
        public SaveResult Add(ThuTucResult entity)
        {
            return(ExecuteDbWithHandle(_logService, () =>
            {
                using (var context = new TechOfficeEntities())
                {
                    using (var transaction = context.BeginTransaction())
                    {
                        var add = entity.AddToDb(context);
                        var result = context.SaveChanges() > 0 ? SaveResult.SUCCESS : SaveResult.FAILURE;

                        transaction.Commit();

                        entity.Id = add.Id;

                        return result;
                    }
                }
            }));
        }
Ejemplo n.º 5
0
        public SaveResult AddTacNghiepWithTinhHinhThucHien(TacNghiepResult entity)
        {
            return(ExecuteDbWithHandle(_logService, () =>
            {
                var result = SaveResult.FAILURE;

                using (var context = new TechOfficeEntities())
                {
                    using (var transaction = context.BeginTransaction())
                    {
                        entity.AddToDb(context);
                        var tt = context.TacNghieps.Local.FirstOrDefault();
                        if (tt != null)
                        {
                            foreach (var item in entity.CoQuanInfos)
                            {
                                var co = context.TacNghiep_TinhHinhThucHien.Create();

                                co.CoQuanId = item.Id;
                                co.TacNghiepId = tt.Id;
                                co.MucDoHoanThanhId = (int)EnumMucDoHoanThanh.CHUATHUHIEN;

                                co.IsDeleted = tt.IsDeleted;
                                co.CreatedBy = tt.CreatedBy;
                                co.CreateDate = tt.CreateDate;

                                context.Entry(co).State = EntityState.Added;
                            }
                        }
                        result = context.SaveChanges() > 0 ? SaveResult.SUCCESS : SaveResult.FAILURE;

                        transaction.Commit();

                        entity.Id = tt.Id;
                    }
                }
                return result;
            }));
        }
Ejemplo n.º 6
0
        public SaveResult AddRange(IEnumerable <ThuTucResult> entities)
        {
            return(ExecuteDbWithHandle(_logService, () =>
            {
                using (var context = new TechOfficeEntities())
                {
                    using (var transaction = context.BeginTransaction())
                    {
                        foreach (var entity in entities)
                        {
                            entity.AddToDb(context);
                        }

                        var result = context.SaveChanges() > 0 ? SaveResult.SUCCESS : SaveResult.FAILURE;

                        transaction.Commit();

                        return result;
                    }
                }
            }));
        }
Ejemplo n.º 7
0
        public SaveResult AddCongViecWithChildren(HoSoCongViecResult entity)
        {
            return(ExecuteDbWithHandle(_logService, () =>
            {
                var saveResult = SaveResult.FAILURE;

                using (var context = new TechOfficeEntities())
                {
                    using (var transaction = context.BeginTransaction())
                    {
                        entity.AddWithChildrenToDb(context);
                        var cv = context.HoSoCongViecs.Local.FirstOrDefault();

                        saveResult = context.SaveChanges() > 0 ? SaveResult.SUCCESS : SaveResult.FAILURE;
                        transaction.Commit();

                        entity.Id = cv != null ? cv.Id : 0;

                        return saveResult;
                    }
                }
            }));
        }