Exemplo n.º 1
0
        public async Task <IActionResult> CreateGroup(NewGroupDTO model)
        {
            try
            {
                if (model.ParentGroupId.HasValue && db.Groups.Find(model.ParentGroupId.Value) == null)  // Parent group with id not found
                {
                    return(BadRequest());
                }

                var groupWithNameExists = await db.Groups.AnyAsync(gr => gr.Name == model.Name);

                if (groupWithNameExists)
                {
                    ModelState.AddModelError("Name", "Group with given name already exists");
                    return(Conflict(ModelState));
                }

                var createdGroup = await db.Groups.AddAsync(new Group()
                {
                    Name        = model.Name,
                    Description = model.Description,
                    ParentId    = model.ParentGroupId,
                });

                await db.SaveChangesAsync();

                return(CreatedAtAction(nameof(CreateGroup), createdGroup.Entity.GroupId));
            }
            catch (Exception)
            {
                return(StatusCode((int)HttpStatusCode.InternalServerError));
            }
        }
Exemplo n.º 2
0
        public async Task <string> CreateGroup(string userId, string groupName)
        {
            NewGroupDTO data = new NewGroupDTO {
                userId = userId, groupName = groupName
            };
            var json          = JsonConvert.SerializeObject(data);
            var stringContent = new StringContent(json, Encoding.UTF8, "application/json");

            try
            {
                var response = await client.PostAsync("http://194.5.157.98:88/api/Group", stringContent);

                response.EnsureSuccessStatusCode();
                if (response != null)
                {
                    return(response.ToString());
                }
            }
            catch (Exception ex)
            {
                Logger.Log(string.Format("CreateGroup: {0}", ex.ToString()));
            }

            return("Unexpected error");
        }
 public bool CreateGroup(NewGroupDTO request)
 {
     try
     {
         return(_GroupsRepo.CreateGroup(request.ClientId, request.LevelId, request.CycleId, request.ShortName, request.MinDate, request.MaxDate));
     }
     catch (Exception e)
     {
         return(false);
     }
 }
Exemplo n.º 4
0
 public async Task <IActionResult> createGroup(NewGroupDTO data)
 {
     if (await Task.Run(() => grp.CreateGroup(data)))
     {
         return(Ok("Group created"));
     }
     else
     {
         return(BadRequest("Group not created"));
     }
 }
Exemplo n.º 5
0
 public Task <bool> CreateGroup(NewGroupDTO data) => Task.Run(() =>
 {
     Groups group = new Groups
     {
         Groupid    = Guid.NewGuid().ToString(),
         Groupmoney = 0,
         Groupname  = data.groupName
     };
     context.Groups.Add(group);
     Userandgroup tuple = new Userandgroup
     {
         Userid  = data.userId,
         Groupid = group.Groupid
     };
     context.Userandgroup.Add(tuple);
     context.SaveChanges();
     bup.createNewBudget(new GetBudgetDTO {
         ownerId = group.Groupid
     });
     return(true);
 });
Exemplo n.º 6
0
 public async Task <GroupDTO> Create(NewGroupDTO group)
 {
     return(await _groupService.Create(group));
 }