Ejemplo n.º 1
0
        public void Can_update()
        {
            var existingItems = new List <string> {
                "Value1"
            };
            var newItems = new List <string> {
                "Value1"
            };

            IList <string> create = new List <string>();
            IList <string> update = new List <string>();
            IList <string> delete = new List <string>();

            CrudHelper.Crud(existingItems, newItems, x => x, ref create, ref update, ref delete);

            // Created
            Assert.AreEqual(0, create.Count);

            // Deleted
            Assert.AreEqual(0, delete.Count);

            // Updated
            Assert.AreEqual(1, update.Count);
            Assert.AreEqual("Value1", update[0]);
        }
        public Response UpdateDepartment()
        {
            var res = new Response();

            if (userInfo.code != 200)
            {
                res.code    = userInfo.code;
                res.message = userInfo.message;
                return(res);
            }
            var departRes = wx.GetDepartmentList();

            if (departRes.code != 200)
            {
                res.code    = departRes.code;
                res.message = departRes.message;
                return(res);
            }
            List <Dictionary <string, object> > list = Json.ToList <Dictionary <string, object> >(departRes.Result);
            List <Department> listDepart             = new List <Department>();

            foreach (var dict in list)
            {
                Department d = new Department();
                d.Id       = Convert.ToInt32(dict["id"]);
                d.Name     = dict["name"].ToString();
                d.ParentId = Convert.ToInt32(dict["parentid"]);
                d.Order    = Convert.ToInt64(dict["order"]);
                listDepart.Add(d);
            }
            int rootIndex = -1;

            for (int i = 0; i < listDepart.Count; i++)
            {
                if (listDepart[i].ParentId == 0)
                {
                    rootIndex = i;
                    listDepart[rootIndex].FullName = listDepart[rootIndex].Name;
                    break;
                }
            }

            SetAllSubDepartmentFullNameAndParentName(ref listDepart, rootIndex);

            try
            {
                CrudHelper <Department> crud = new CrudHelper <Department>("department");
                crud.Delete();
                crud.Add(listDepart, true);
            }
            catch (Exception e)
            {
                res.code    = 500;
                res.message = e.ToString();
            }


            return(res);
        }
Ejemplo n.º 3
0
        public virtual TEntity GetAndInclude <TEntity>(TEntity entity, string property) where TEntity : class
        {
            var keys = Crud.Secured.IdProperties.Select(p => new KeyValuePair <string, object>(p.Name, entity.GetPropertyValue(p.Name)))
                       .ToArray();
            var expression = CrudHelper.KeyEqualsExpression <TEntity>(keys);

            return(Crud.Secured.Context.Set <TEntity>().Include(property).Where(
                       expression).SingleOrDefault());
        }
Ejemplo n.º 4
0
        public async Task Update_NotFound_Async()
        {
            var updateItem = new TestItemBare();

            updateItem.InitializeWithDataForTesting(TypeOfTestDataEnum.Default);
            await CrudStorage.UpdateAsync(CrudHelper.CreateNewId <TId>(), updateItem);

            Assert.Fail("Expected an exception");
        }
        public Constructor(string fullFilePath, Topology.Topology topology)
        {
            this.fullFilePath = fullFilePath ?? throw new NullReferenceException();

            if (topology == null)
            {
                throw new NullReferenceException();
            }

            InitializeComponent();
            connection = ConnectionHelpers.OpenConnection();
            crudHelper = new CrudHelper(connection);

            SetupSettings();
            topologyBuilder = new TopologyBuilder(dgvField, topology);
        }
        public AddNewFuel(CrudHelper crudHelper, FuelTank fuelTank)
        {
            if (crudHelper == null ||
                fuelTank == null)
            {
                throw new NullReferenceException();
            }

            InitializeComponent();

            this.crudHelper = crudHelper;
            this.fuelTank   = fuelTank;

            labelWrongFuelName.Visible = false;
            nudCostPerLiter.Minimum    = CashCounter.MinPricePerLiterOfFuelInRubles;
            nudCostPerLiter.Maximum    = CashCounter.MaxPricePerLiterOfFuelInRubles;
        }
        public Response <List <Client> > GetByName(string name)
        {
            var res = new Response <List <Client> >();

            if (userInfo.code != 200)
            {
                res.code    = userInfo.code;
                res.message = userInfo.message;
                return(res);
            }
            try
            {
                CrudHelper <Client> crud = new CrudHelper <Client>("client");
                res.Result = crud.GetList(string.Format("Name like '%{0}%'", name));
            }
            catch (Exception e)
            {
                res.code    = 500;
                res.message = e.Message;
            }

            return(res);
        }
        public Constructor(string fullFilePath, int cols, int rows)
        {
            this.fullFilePath = fullFilePath ?? throw new NullReferenceException();

            if (cols < Topology.Topology.MinColsCount ||
                cols > Topology.Topology.MaxColsCount)
            {
                throw new ArgumentOutOfRangeException();
            }

            if (rows < Topology.Topology.MinRowsCount ||
                rows > Topology.Topology.MaxRowsCount)
            {
                throw new ArgumentOutOfRangeException();
            }

            InitializeComponent();
            connection = ConnectionHelpers.OpenConnection();
            crudHelper = new CrudHelper(connection);

            SetupSettings();
            topologyBuilder = new TopologyBuilder(dgvField, cols, rows);;
        }
        public Response UpdateAllUserInfo()
        {
            var res = new Response();

            if (userInfo.code != 200)
            {
                res.code    = userInfo.code;
                res.message = userInfo.message;
                return(res);
            }
            var userRes = wx.GetUserList();

            if (userRes.code != 200)
            {
                res.code    = userRes.code;
                res.message = userRes.message;
                return(res);
            }
            List <Dictionary <string, object> > list = Json.ToList <Dictionary <string, object> >(userRes.Result);

            try
            {
                CrudHelper <User>     uCrud   = new CrudHelper <User>("user");
                List <User>           oldList = uCrud.GetList();
                List <User>           newList = new List <User>();
                List <UserDepartment> udList  = new List <UserDepartment>();

                for (int i = 0; i < oldList.Count; i++)
                {
                    oldList[i].Status = "2";//将已存如本地数据库,但未在企业微信找到的用户状态置为禁用
                }
                foreach (var dict in list)
                {
                    int    index        = -1;
                    string WechatUserId = dict["userid"].ToString();
                    for (int i = 0; i < oldList.Count; i++)
                    {
                        if (oldList[i].WechatUserId == WechatUserId)
                        {
                            index = i;
                            break;
                        }
                    }
                    if (index >= 0)
                    {
                        User u = oldList[index];
                        u.UserName = ToolDictionary.GetValueString("name", dict);
                        u.Address  = ToolDictionary.GetValueString("address", dict);
                        u.Avatar   = ToolDictionary.GetValueString("avatar", dict);
                        u.Email    = ToolDictionary.GetValueString("email", dict);
                        u.Gender   = ToolDictionary.GetValueString("gender", dict);
                        u.Mobile   = ToolDictionary.GetValueString("mobile", dict);
                        u.Position = ToolDictionary.GetValueString("position", dict);
                        u.Status   = ToolDictionary.GetValueString("status", dict);
                    }
                    else
                    {
                        User u = new User();
                        u.WechatUserId = WechatUserId;
                        u.UserName     = ToolDictionary.GetValueString("name", dict);
                        u.Address      = ToolDictionary.GetValueString("address", dict);
                        u.Avatar       = ToolDictionary.GetValueString("avatar", dict);
                        u.Email        = ToolDictionary.GetValueString("email", dict);
                        u.Gender       = ToolDictionary.GetValueString("gender", dict);
                        u.Mobile       = ToolDictionary.GetValueString("mobile", dict);
                        u.Position     = ToolDictionary.GetValueString("position", dict);
                        u.Status       = ToolDictionary.GetValueString("status", dict);
                        newList.Add(u);
                    }

                    //构建UserDepartment数据
                    List <int> dl = Json.ToList <int>(dict["department"].ToString());
                    List <int> ol = Json.ToList <int>(dict["order"].ToString());
                    List <int> ll = Json.ToList <int>(dict["is_leader_in_dept"].ToString());
                    for (int i = 0; i < dl.Count; i++)
                    {
                        UserDepartment ud = new UserDepartment();
                        ud.WechatUserId = WechatUserId;
                        ud.DepartmentId = dl[i];
                        ud.IsLeader     = ll[i];
                        ud.Order        = ol[i];
                        udList.Add(ud);
                    }
                }
                CrudHelper <UserDepartment> udCrud = new CrudHelper <UserDepartment>("user_department");
                uCrud.Update(oldList);
                uCrud.Add(newList);
                udCrud.Delete();
                udCrud.Add(udList);
            }
            catch (Exception e)
            {
                res.code    = 500;
                res.message = e.ToString();
            }

            List <Department> listDepart = new List <Department>();


            return(res);
        }
 public async Task Delete_NotFound()
 {
     await CrdStorage.DeleteAsync(CrudHelper.CreateNewId <TId>());
 }
        public async Task Read_NotFound_Async()
        {
            var item = await CrdStorage.ReadAsync(CrudHelper.CreateNewId <TId>());

            Microsoft.VisualStudio.TestTools.UnitTesting.Assert.IsNull(item);
        }
Ejemplo n.º 12
0
        public async Task Read_NotFound_Async()
        {
            var item = await CrdStorage.ReadAsync(CrudHelper.CreateNewId <TId>());

            Assert.IsNull(item);
        }