Esempio n. 1
0
        public bool CreateGroup(GroupCreateRAO model)
        {
            var newGroup = new GroupEntity
            {
                GroupName      = model.GroupName,
                OwnerId        = _userId,
                GroupInviteKey = GenerateRandomString(8)
            };

            using (var ctx = new ApplicationDbContext())
            {
                ctx.Groups.Add(newGroup);

                if (ctx.SaveChanges() != 1)
                {
                    return(false);
                }

                var groups = ctx.Groups.Where(g => g.OwnerId == newGroup.OwnerId).ToList();
                var id     = groups[(groups.Count() - 1)].GroupId;

                var groupMember = new GroupMemberEntity
                {
                    MemberId = _userId,
                    GroupId  = id,
                    InGroup  = true,
                    IsMod    = true
                };

                ctx.GroupMembers.Add(groupMember);
                return(ctx.SaveChanges() == 1);
            }
        }
Esempio n. 2
0
        public IHttpActionResult CreateGroup(GroupCreateDTO dto)
        {
            var service = GetGroupService();

            var rao = new GroupCreateRAO
            {
                GroupName = dto.GroupName
            };

            if (service.CreateGroup(rao))
            {
                return(Ok());
            }
            else
            {
                return(BadRequest());
            }
        }
Esempio n. 3
0
        public ActionResult Create(GroupCreateDTO dto)
        {
            if (!ModelState.IsValid)
            {
                return(View(dto));
            }

            var svc = GetGroupService();
            var rao = new GroupCreateRAO {
                GroupName = dto.GroupName
            };

            if (svc.CreateGroup(rao))
            {
                var id = svc.GetGroupIDByName(rao.GroupName);
                return(RedirectToAction("Index", new { id }));
            }

            TempData["FailResult"] = "Cannot create group.";
            return(View());
        }