Beispiel #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="team"></param>
        /// <returns></returns>
        public OperationResult <ModelOrg> Create(ModelOrg org, bool addMembership = true)
        {
            OperationResult <ModelOrg> res;

            try
            {
                var entity = org.ToEntity();

                DataContext.Add(entity);

                DataContext.SaveChanges();

                var model = entity.ToModel();

                org.Id = model.Id;

                if (addMembership)
                {
                    DataContext.OrgMember.Add(new OrgMember(entity.Id, DataContext.ActiveUserId));
                    DataContext.SaveChanges();
                }

                res = OperationResult <ModelOrg> .Create(model);
            }
            catch (Exception e)
            {
                res = OperationResult <ModelOrg> .Create(ErrorCode.BadCreateOrg, e);
            }

            return(res);
        }
Beispiel #2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="team"></param>
        /// <returns></returns>
        public OperationResult <ModelOrg> Update(ModelOrg org)
        {
            OperationResult <ModelOrg> res;

            try
            {
                var entity = org.ToEntity();

                DataContext.Update(entity);

                DataContext.SaveChanges();

                var model = entity.ToModel();

                res = OperationResult <ModelOrg> .Create(model);

                IncrementUsersVersion(org.Id);
            }
            catch (Exception e)
            {
                res = OperationResult <ModelOrg> .Create(ErrorCode.BadUpdateOrg, e);
            }

            return(res);
        }
Beispiel #3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="dc"></param>
        public static ModelOrgs AddOrgs(this DataContext dc, int count = 3)
        {
            var repo = new OrgRepository(dc);

            var companies = TestFactory.GetRandomCompanyNames(count);
            var list      = new ModelOrgs();

            foreach (var c in companies)
            {
                var o = new ModelOrg()
                {
                    Name = c
                };

                var op = repo.Create(o, false);
                o.Id = op.Value.Id;

                list.Add(o);
            }

            return(list);
        }