private GroupBindingModel CreateGroupBindingModel(BindingGroup groupBinding)
        {
            GroupTypes grpCtrl = GroupTypes.Display;

            // determine the type of group binding
            if (groupBinding.Control != null)
            {
                grpCtrl = groupBinding.Control.GroupType;
            }

            GroupBindingModel gbm = null;

            // create the group binding model type
            switch (grpCtrl)
            {
            case GroupTypes.Display:
                gbm = new DisplayGroupBindingModel();
                break;

            case GroupTypes.Options:
                gbm = new OptionsGroupBindingModel();
                break;
            }

            return(gbm);
        }
        public async Task <IHttpActionResult> PostGroup(GroupBindingModel model)
        {
            var userId      = this.User.Identity.GetUserId();
            var currentUser = await this.Data.Users.All().Where(u => u.Id == userId).ToListAsync();

            if (!this.ModelState.IsValid)
            {
                return(this.BadRequest(this.ModelState));
            }

            if (model == null)
            {
                return(this.BadRequest("Invalid input data"));
            }

            if (userId == null)
            {
                return(this.BadRequest("Invalid session token."));
            }

            var group = new Group()
            {
                Name        = model.Name,
                CreatedOn   = DateTime.Now,
                Description = model.Description ?? null,
                Users       = currentUser
            };

            this.Data.Groups.Add(group);
            await this.Data.SaveChangesAsync();

            return(this.StatusCode(HttpStatusCode.Created));
        }
Пример #3
0
        protected virtual void NavigateGroup(GroupBindingModel bindingModel)
        {
            var optionsGroupBindingModel = bindingModel as OptionsGroupBindingModel;

            // special case for option group
            if (optionsGroupBindingModel != null && !NavigateAll)
            {
                bool hasSubGroups = bindingModel.GroupBindings.Any();

                // is it a GroupOptoinsContainerControl i.e. Tabs?
                if (hasSubGroups)
                {
                    foreach (var valueBindingModel in bindingModel.ValueBindings)
                    {
                        NavigateValue(valueBindingModel);
                    }
                }

                Navigate(optionsGroupBindingModel.SelectedOption);
            }
            else
            {
                foreach (var binding in bindingModel.Bindings)
                {
                    Navigate(binding);
                }
            }
        }
        public IHttpActionResult PostUsersGroups(GroupBindingModel groupBM)
        {
            if (groupBM.UserGroupList == null)
            {
                return(BadRequest());
            }

            var identity = (ClaimsIdentity)User.Identity;
            IEnumerable <Claim> claims = identity.Claims;
            var userId = int.Parse(claims.Where(c => c.Type == ClaimTypes.NameIdentifier).FirstOrDefault().Value);


            groupBM.UserGroupList.Remove(groupBM.UserGroupList.Where(ug => ug.UserId == userId).FirstOrDefault());
            groupBM.UserId = userId;

            var userGroupList = AutoMapper.Mapper.Map <List <UserGroupBindingModel>, List <UserGroup> >(groupBM.UserGroupList);


            try
            {
                userGroupService.AddUserGroup(userGroupList, groupBM.Name, userId);
                unitOfWork.Commit();
            }
            catch (Exception e)
            {
                if (ModelState.Count() == 0)
                {
                    ModelState.AddModelError("", "Postoji grupa sa unetim imenom");
                }
                return(BadRequest(ModelState));
            }

            return(Ok());
        }
Пример #5
0
 public void Insert(GroupBindingModel model)
 {
     using (var context = new JournalDb())
     {
         context.Groups.Add(CreateModel(model, new Group()));
         context.SaveChanges();
     }
 }
        private void Fill(GroupBindingModel groupBindingModel, BindingGroup bindingGroup)
        {
            groupBindingModel.Description = bindingGroup.Description;
            groupBindingModel.Name        = bindingGroup.Name;
            groupBindingModel.Properties  = bindingGroup.PropertyBag;
            groupBindingModel.HelpInfo    = CreateHelpInfo(bindingGroup);

            if (bindingGroup.Control != null)
            {
                groupBindingModel.Control.Properties = bindingGroup.Control.PropertyBag;
            }

            for (int index = 0; index < bindingGroup.BindingGroupsAndBindings.Count; index++)
            {
                var bindingSubGroup = bindingGroup.BindingGroupsAndBindings[index] as BindingGroup;
                var binding         = bindingGroup.BindingGroupsAndBindings[index] as Binding;

                if (bindingSubGroup != null)
                {
                    var subGroupBindingModel = CreateGroupBindingModel(bindingSubGroup);

                    Fill(subGroupBindingModel, bindingSubGroup);

                    subGroupBindingModel.Parent = groupBindingModel;
                    groupBindingModel.Bindings.Add(subGroupBindingModel);
                }

                if (binding != null)
                {
                    var bindingModel = CreateValueBindingModel(binding);

                    bindingModel.Parent = groupBindingModel;
                    groupBindingModel.Bindings.Add(bindingModel);
                }
            }

            var ogbm = groupBindingModel as OptionsGroupBindingModel;

            if (ogbm != null)
            {
                // preselect the first option
                ogbm.SelectedOption = (from binding in ogbm.GroupBindings
                                       select binding).FirstOrDefault();

                // hide group labels for the first level of group binding children.
                // They are shown as tabs.
                foreach (var group in ogbm.GroupBindings)
                {
                    var displayGroup = group as DisplayGroupBindingModel;

                    if (displayGroup != null)
                    {
                        displayGroup.ShowGroupName = false;
                    }
                }
            }
        }
Пример #7
0
        public void CreateOrUpdate(GroupBindingModel model)
        {
            using (var context = new CampDatabase())
            {
                using (var transaction = context.Database.BeginTransaction())
                {
                    Group group;

                    if (model.Id.HasValue)
                    {
                        group = context.Groups.FirstOrDefault(rec => rec.Id ==
                                                              model.Id);
                        if (group == null)
                        {
                            throw new Exception("Элемент не найден");
                        }
                    }
                    else
                    {
                        group = new Group();
                        context.Groups.Add(group);
                    }
                    //group.CounsellorId = model.CounsellorId == 0 ? group.CounsellorId : model.CounsellorId;
                    group.Name    = model.Name;
                    group.Profile = model.Profile;
                    context.SaveChanges();
                    if (model.Id.HasValue)
                    {
                        // нашли детей, входящих в эту группу
                        var Children = context.Children.Where(rec
                                                              => rec.GroupId == model.Id.Value).ToList();
                        // у каждого ребёнка изменили значение группы
                        foreach (var child in Children)
                        {
                            child.GroupId = model.Id;
                        }
                    }
                    // добавили новые
                    foreach (var child in context.Children)
                    {
                        if (model.Children.ContainsKey(child.Id))
                        {
                            child.GroupId = group.Id;
                        }
                    }
                    if (model.CounselorId != 0 && model.CounselorId != null)
                    {
                        var Counselor = context.Counsellors.Where(x => x.Id == model.CounselorId).ToList()[0];
                        Counselor.GroupId = group.Id;
                    }
                    context.SaveChanges();

                    transaction.Commit();
                }
            }
        }
Пример #8
0
 public List <GroupViewModel> Read(GroupBindingModel model)
 {
     if (model == null)
     {
         return(groupStorage.GetFullList());
     }
     return(new List <GroupViewModel> {
         groupStorage.GetElement(model)
     });
 }
Пример #9
0
 private void AddParent(GroupBindingModel parent)
 {
     if (_refCounts.ContainsKey(parent))
     {
         _refCounts[parent] = _refCounts[parent] + 1;
     }
     else
     {
         _refCounts[parent] = 1;
     }
 }
Пример #10
0
        /// <summary>
        /// Builds the command line.
        /// </summary>
        /// <param name="bindingModel">Must not be null.</param>
        /// <returns></returns>
        public string Build(GroupBindingModel bindingModel)
        {
            _ctx = new CommandLineContext();

            NavigateGroup(bindingModel);

            var commandLine = Compile(_ctx);

            _ctx = null;

            return(commandLine);
        }
Пример #11
0
        public void CreateOrUpdate(GroupBindingModel model)
        {
            using (var context = new CampDatabase())
            {
                using (var transaction = context.Database.BeginTransaction())
                {
                    Group group;

                    if (model.Id.HasValue)
                    {
                        group = context.Groups.FirstOrDefault(rec => rec.Id ==
                                                              model.Id);
                        if (group == null)
                        {
                            throw new Exception("Элемент не найден");
                        }
                    }
                    else
                    {
                        group = new Group();
                        context.Groups.Add(group);
                    }
                    group.CounsellorId = model.CounsellorId == 0 ? group.CounsellorId : model.CounsellorId;
                    group.Name         = model.Name;
                    group.Profile      = model.Profile;
                    context.SaveChanges();
                    if (model.Id.HasValue)
                    {
                        // нашли детей, входящих в эту группу
                        var Children = context.Children.Where(rec
                                                              => rec.GroupId == model.Id.Value).ToList();
                        // у каждого ребёнка обнулили значение группы
                        foreach (var child in Children)
                        {
                            //logic.DeleteChildFromGroup(child.Id);
                            child.GroupId = 0;
                        }
                    }
                    // добавили новые
                    foreach (var child in model.Children)
                    {
                        context.Children.Add(new Child
                        {
                            GroupId = group.Id,
                            Id      = child.Key,
                        });
                        context.SaveChanges();
                    }
                    transaction.Commit();
                }
            }
        }
Пример #12
0
        public void Delete(GroupBindingModel model)
        {
            var element = groupStorage.GetElement(new GroupBindingModel
            {
                Id = model.Id
            });

            if (element == null)
            {
                throw new Exception("Группа не найден");
            }
            groupStorage.Delete(model);
        }
 public List <GroupViewModel> Read(GroupBindingModel model)
 {
     if (model == null)
     {
         return(_groupStorage.GetFullList());
     }
     if (model.Id.HasValue)
     {
         return(new List <GroupViewModel> {
             _groupStorage.GetElement(model)
         });
     }
     return(_groupStorage.GetFilteredList(model));
 }
Пример #14
0
        public void Delete(GroupBindingModel model)
        {
            using (var context = new JournalDb())
            {
                var group = context.Groups.FirstOrDefault(rec => rec.Id == model.Id);

                if (group == null)
                {
                    throw new Exception("Группа не найдена");
                }

                context.Groups.Remove(group);
                context.SaveChanges();
            }
        }
Пример #15
0
        public IHttpActionResult Update(GroupBindingModel GroupBM)
        {
            try
            {
                var group = Mapper.Map <GroupBindingModel, Group>(GroupBM);
                _groupService.Update(group);

                GroupBM = Mapper.Map <Group, GroupBindingModel>(group);
                return(Ok(GroupBM));
            }
            catch (Exception ex)
            {
                var result = ex.Message;
            }
            return(Ok(StatusCode(HttpStatusCode.BadRequest)));
        }
Пример #16
0
        private void FillGroup(GroupBindingModel bindingModel, CommandLineContext ctx)
        {
            var optionsGroupBindingModel = bindingModel as OptionsGroupBindingModel;

            if (optionsGroupBindingModel != null)
            {
                Fill(optionsGroupBindingModel.SelectedOption, ctx);
            }
            else
            {
                foreach (var binding in bindingModel.Bindings)
                {
                    Fill(binding, ctx);
                }
            }
        }
Пример #17
0
 public IHttpActionResult Delete(Guid id)
 {
     try
     {
         var GroupBM = new GroupBindingModel()
         {
             Id = id
         };
         var group = Mapper.Map <GroupBindingModel, Image>(GroupBM);
         _groupService.Delete(group.Id);
         return(Ok());
     }
     catch (Exception ex)
     {
         var result = ex.Message;
     }
     return(Ok(StatusCode(HttpStatusCode.BadRequest)));
 }
Пример #18
0
 public List <GroupViewModel> Read(GroupBindingModel model)
 {
     using (var context = new CampDatabase())
     {
         return(context.Groups
                .Where(rec => model == null ||
                       (rec.Id == model.Id && model.Id.HasValue))
                .Select(rec => new GroupViewModel
         {
             Id = rec.Id,
             CounsellorId = context.Counsellors.Where(x => x.GroupId == rec.Id).First().Id,
             CounsellorName = context.Counsellors.Where(x => x.GroupId == rec.Id).First().FIO,
             Name = rec.Name,
             Profile = rec.Profile,
         })
                .ToList());
     }
 }
Пример #19
0
 public List <GroupViewModel> Read(GroupBindingModel model)
 {
     using (var context = new CampDatabase())
     {
         return(context.Groups
                .Include(rec => rec.children)
                .Where(rec => model == null ||
                       (rec.Id == model.Id && model.Id.HasValue) &&
                       (rec.Profile <= model.Profile))
                .Select(rec => new GroupViewModel
         {
             Id = rec.Id,
             CounsellorId = rec.CounsellorId,
             Name = rec.Name,
             Profile = rec.Profile,
         })
                .ToList());
     }
 }
Пример #20
0
        public void CreateOrUpdate(GroupBindingModel model)
        {
            var element = groupStorage.GetElement(new GroupBindingModel
            {
                NameGroup = model.NameGroup
            });

            if (element != null && element.Id != model.Id)
            {
                throw new Exception("Уже присутствует такая группа");
            }
            if (model.Id.HasValue)
            {
                groupStorage.Update(model);
            }
            else
            {
                groupStorage.Insert(model);
            }
        }
Пример #21
0
 public GroupViewModel GetElement(GroupBindingModel model)
 {
     if (model == null)
     {
         return(null);
     }
     using (var context = new Context())
     {
         var group = context.Groups.Include(rec => rec.OrderGroups)
                     .ThenInclude(rec => rec.Order)
                     .Include(rec => rec.Customer)
                     .FirstOrDefault(rec => rec.Id == model.Id);
         return(group != null ?
                new GroupViewModel
         {
             Id = group.Id,
             Name = group.Name,
             CuratorName = group.CuratorName
         } : null);
     }
 }
Пример #22
0
        public GroupViewModel GetElement(GroupBindingModel model)
        {
            if (model == null)
            {
                return(null);
            }
            using (var context = new JournalDb())
            {
                var group = context.Groups
                            .FirstOrDefault(rec => rec.NameGroup == model.NameGroup ||
                                            rec.Id == model.Id);

                return(group != null ?
                       new GroupViewModel
                {
                    Id = group.Id,
                    NameGroup = group.NameGroup
                } :
                       null);
            }
        }
Пример #23
0
 public List <GroupViewModel> GetFilteredList(GroupBindingModel model)
 {
     if (model == null)
     {
         return(null);
     }
     using (var context = new Context())
     {
         return(context.Groups
                .Include(rec => rec.OrderGroups)
                .ThenInclude(rec => rec.Order)
                .Where(rec => rec.Id == model.Id)
                .ToList()
                .Select(rec => new GroupViewModel
         {
             Id = rec.Id,
             Name = rec.Name,
             CuratorName = rec.CuratorName
         })
                .ToList());
     }
 }
Пример #24
0
        public IHttpActionResult Save(GroupBindingModel GroupBM)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    var group = Mapper.Map <GroupBindingModel, Group>(GroupBM);
                    _groupService.Save(group);

                    GroupBM = Mapper.Map <Group, GroupBindingModel>(group);
                    return(Ok(GroupBM));
                }
                catch (Exception ex)
                {
                    var result = ex.Message;
                }
            }
            else
            {
                return(BadRequest(ModelState));
            }
            return(Ok(StatusCode(HttpStatusCode.BadRequest)));
        }
Пример #25
0
 public void Delete(GroupBindingModel model)
 {
     using (var context = new CampDatabase())
     {
         Group group = context.Groups.FirstOrDefault(rec => rec.Id == model.Id);
         if (group != null)
         {
             // нашли детей, входящих в эту группу
             var Children = context.Children.Where(rec
                                                   => rec.GroupId == model.Id.Value).ToList();
             // у каждого ребёнка обнулили значение группы
             foreach (var child in Children)
             {
                 child.GroupId = 0;
             }
             context.Groups.Remove(group);
             context.SaveChanges();
         }
         else
         {
             throw new Exception("Элемент не найден");
         }
     }
 }
Пример #26
0
        public IHttpActionResult Update(int id, GroupBindingModel groupBM)
        {
            //get user
            var userId = int.Parse(((ClaimsIdentity)User.Identity).Claims.Where(c => c.Type == ClaimTypes.NameIdentifier).FirstOrDefault().Value);
            var old    = groupService.Get(id);

            if (old.UserId != userId)
            {
                return(Unauthorized());
            }
            groupBM.UserId = userId;
            var group = AutoMapper.Mapper.Map <GroupBindingModel, Group>(groupBM);

            try
            {
                groupService.Update(old, group);
                unitOfWork.Commit();
                return(Ok());
            }
            catch (Exception)
            {
                return(BadRequest());
            }
        }
Пример #27
0
 private Group CreateModel(GroupBindingModel model, Group group)
 {
     group.NameGroup = model.NameGroup;
     return(group);
 }