Ejemplo n.º 1
0
        public async Task <BaseResponse <int> > CreateAsync(GroupCreateModel model, string parentSequenceCode, int orgId, int createdBy)
        {
            try
            {
                var pars = new DynamicParameters();
                pars.Add("Id", dbType: DbType.Int32, direction: ParameterDirection.Output);
                pars.Add("parentId", model.ParentId);
                pars.Add("LeaderId", model.LeaderId);
                pars.Add("ShortName", model.ShortName);
                pars.Add("Name", model.Name);
                pars.Add("parentSequenceCode", parentSequenceCode);
                pars.Add("orgId", orgId);
                pars.Add("createdBy", createdBy);
                pars.Add("memberIds", string.Join(',', model.MemberIds));
                using (var con = GetConnection())
                {
                    var result = await con.ExecuteAsync("sp_Group_Create",
                                                        pars,
                                                        commandType : CommandType.StoredProcedure);

                    return(BaseResponse <int> .Create(pars.Get <int>("Id")));
                }
            }
            catch (Exception ex)
            {
                return(BaseResponse <int> .Create(0, GetException(ex)));
            }
        }
Ejemplo n.º 2
0
        public ActionResult CreateGroup(GroupCreateModel model, String userId)
        {
            var groupService = this.Service <IGroupService>();

            var groupMemberService = this.Service <IGroupMemberService>();

            ResponseModel <GroupViewModel> response = null;

            try {
                Group group = Mapper.Map <Group>(model);

                if (model.UploadImage != null)
                {
                    FileUploader uploader = new FileUploader();

                    group.Avatar = uploader.UploadImage(model.UploadImage, userImagePath);
                }

                group = groupService.CreateGroup(group);

                groupMemberService.CreateGroupAdmin(group.Id, userId);

                GroupViewModel result = Mapper.Map <GroupViewModel>(group);

                response = new ResponseModel <GroupViewModel>(true, "Tạo nhóm thành công", null, result);
            } catch (Exception) {
                response = ResponseModel <GroupViewModel> .CreateErrorResponse("Tạo nhóm thất bại!", systemError);
            }

            return(Json(response));
        }
Ejemplo n.º 3
0
        public async Task <Response> Create(GroupCreateModel GroupCreateModel, ClaimsPrincipal user)
        {
            using (var context = _applicationDbContextFactory.Create())
            {
                var User = await _userManager.FindByNameAsync(user.Identity.Name);

                var Group = Mapper.Map <Group>(GroupCreateModel);
                if (context.Groups.Any(i => i.Name == Group.Name))
                {
                    return new Response {
                               Status = 500, Message = "Такая группа уже существует!"
                    }
                }
                ;
                if (!context.Check <Group>(Group.TeacherId))
                {
                    return new Response {
                               Status = 500, Message = "Такого учителя нет!"
                    }
                }
                ;

                var Result = context.Groups.Add(Group);
                context.SaveChanges();
                context.groupHistories.Add(new GroupHistory {
                    Action = "Создание", DateTime = DateTime.Now, GroupId = Result.Entity.Id, UserId = User.Id
                });
                context.SaveChanges();
                return(new Response {
                    Status = 100, Message = "Запрос успешно прошел"
                });
            }
        }
Ejemplo n.º 4
0
        public async Task <IActionResult> CreateGroupAsync([FromBody] GroupCreateModel model)
        {
            if (string.IsNullOrWhiteSpace(model.Name))
            {
                throw new IsRequiredException("name");
            }

            if (model.Name.Length > 150)
            {
                throw new NameIsInvalidException();
            }

            if (await _groupRepository.AnyByNameAsync(model.Name))
            {
                throw new AlreadyExistsException("name");
            }

            DateTime now = DateTime.Now;

            var accountId = CurrentAccountId;

            var group = new Group
            {
                Name        = model.Name,
                CreatedDate = now,
                CreatedBy   = accountId,
                UpdatedDate = now,
                UpdatedBy   = accountId
            };

            await _groupRepository.CreateGroupAsync(group);

            return(Ok(GroupDTO.GetFrom(group)));
        }
Ejemplo n.º 5
0
        public async Task <int> CreateAsync(GroupCreateModel model)
        {
            if (model == null)
            {
                return(ToResponse(0, Errors.invalid_data));
            }
            if (string.IsNullOrWhiteSpace(model.Name) || string.IsNullOrWhiteSpace(model.ShortName))
            {
                return(ToResponse(0, "Vui lòng nhập tên nhóm"));
            }

            if (model.MemberIds == null)
            {
                model.MemberIds = new List <int>();
            }

            string parentSequenceCode = "0";

            if (model.ParentId > 0)
            {
                var parentCodeResponse = await _rpGroup.GetParentSequenceCodeAsync(model.ParentId);

                if (parentCodeResponse.success)
                {
                    parentSequenceCode = parentCodeResponse.data + "." + model.ParentId;
                }
            }
            model.MemberIds = model.MemberIds != null?model.MemberIds.Distinct().ToList() : new List <int>();

            return(ToResponse(await _rpGroup.CreateAsync(model, parentSequenceCode, _process.User.OrgId, _process.User.Id)));
        }
Ejemplo n.º 6
0
 public async Task <ActionResult> Create(GroupCreateModel Model)
 {
     if (ModelState.IsValid)
     {
         GroupAddRequest gar = new GroupAddRequest()
         {
             CourseCode    = Model.CourseCode,
             GroupCode     = Model.CourseCode + DateTime.UtcNow.ToString("MMddyyHmmss"),
             GroupName     = Model.GroupName,
             GroupTypeCode = Model.GroupTypeCode,
             Objective     = Model.Objective,
             TimeZone      = Model.TimeZone,
             userList      = new List <string>()
             {
                 User.Identity.Name
             }
         };
         bool resp = _groupCom.AddGroup(gar);
         if (resp)
         {
             return(RedirectToAction("GroupDetail", "Group", routeValues: new { groupCode = gar.GroupCode }));
         }
     }
     ModelState.AddModelError("", "Oops! Something wrong happened! Please try again.");
     return(View(Model));
 }
 public ActionResult Create(GroupCreateModel group)
 {
     if (ModelState.IsValid)
     {
         _groupService.Add(group, User.Identity.GetUserId());
         return(RedirectToAction("Index"));
     }
     return(View(group));
 }
Ejemplo n.º 8
0
 private static Group CreateEntity(Guid memoryBookUniverseId, GroupCreateModel model)
 {
     return(new Group
     {
         MemoryBookUniverseId = memoryBookUniverseId,
         Code = model.Code,
         Name = model.Name,
         Description = model.Description
     });
 }
Ejemplo n.º 9
0
        public ActionResult Create(GroupCreateModel createModel)
        {
            if (!ModelState.IsValid)
            {
                return(RedirectToCurrentUmbracoPage(Request.QueryString));
            }

            var groupId = _groupMemberService.Create(createModel);

            return(Redirect(groupId));
        }
Ejemplo n.º 10
0
        public ActionResult Create()
        {
            var createGroupModel = new GroupCreateModel();
            var mediaSettings    = _mediaHelper.GetMediaFolderSettings(MediaFolderTypeEnum.GroupsContent, true);

            createGroupModel.MediaRootId            = mediaSettings.MediaRootId;
            createGroupModel.CreatorId              = _userService.GetCurrentUserId();
            createGroupModel.AllowedMediaExtensions = mediaSettings.AllowedMediaExtensions;

            return(PartialView(CreateViewPath, createGroupModel));
        }
Ejemplo n.º 11
0
        public IActionResult Create([FromBody] GroupCreateModel model)
        {
            var group = _mapper.Map <Group>(model);

            try
            {
                _groupService.Create(group);
                return(Ok());
            }
            catch (AppException ex)
            {
                return(BadRequest(new { message = ex.Message }));
            }
        }
Ejemplo n.º 12
0
        public IActionResult Update(int groupId, [FromBody] GroupCreateModel model)
        {
            var group = _mapper.Map <Group>(model);

            try
            {
                _groupService.Update(group, groupId);
                return(Ok());
            }
            catch (AppException ex)
            {
                // return error message if there was an exception
                return(BadRequest(new { message = ex.Message }));
            }
        }
Ejemplo n.º 13
0
        public ActionResult Create()
        {
            var currentUser = idb.Users.Find(User.Identity.GetUserId());
            GroupCreateModel _GroupCreateModel = new GroupCreateModel();

            _GroupCreateModel.Locations   = repository.GetLocations().ToList();
            _GroupCreateModel.Hour        = 5;
            _GroupCreateModel.Minute      = 30;
            _GroupCreateModel.CreatorName = currentUser.FirstName + " " + currentUser.LastName;
            Location _Location = repository.GetLocations().Where(l => l.id == currentUser.LocationID).FirstOrDefault();

            _GroupCreateModel.LocationsId = _Location.id;
            _GroupCreateModel.lat         = _Location.Lat;
            _GroupCreateModel.lng         = _Location.Lng;
            return(View(_GroupCreateModel));
        }
Ejemplo n.º 14
0
        public async Task <IActionResult> Create(GroupCreateModel model, IFormFile file)
        {
            if (ModelState.IsValid && file != null)
            {
                Image img = new Image()
                {
                    Path = Path.Combine("/images", file.FileName)
                };
                await _dbContext.Images.AddAsync(img);

                await Uploader.UploadToServer(new Uploader(_environment).DefineImagePath(file), file);

                Group group = new Group()
                {
                    Faculty = _dbContext.Faculties.Where(x => x.Id == model.FacultyId).FirstOrDefault(),
                    CourseCompletionStatusId = 1,
                    CreationDate             = DateTime.Now,
                    IsDeleted        = false,
                    LessonHourId     = model.HourId,
                    RoomId           = model.RoomId,
                    Name             = model.Name,
                    LessonsStartDate = model.StartDate,
                    LessonsEndDate   = model.EndDate,
                    Teacher          = _dbContext.Teachers.FirstOrDefault(x => x.Id == model.TeacherId),
                    ImageId          = img.Id
                };

                TeacherToGroup teacherToGroup = new TeacherToGroup {
                    Group = group, Teacher = group.Teacher, AddingDate = DateTime.Now
                };

                await _dbContext.Groups.AddAsync(group);

                await _dbContext.TeacherToGroups.AddAsync(teacherToGroup);

                if (await _dbContext.SaveChangesAsync() > 0)
                {
                    return(Json("Ok!"));
                }
            }
            else
            {
                ModelState.AddModelError("", "Something is wrong");
            }
            return(RedirectToAction("Index", "Groups"));
        }
Ejemplo n.º 15
0
        public bool Add(GroupCreateModel model, string createdBy)
        {
            var group = new Group();

            group.Name        = model.Name;
            group.Description = model.Description;
            group.UserId      = createdBy;
            try
            {
                _groupRepository.Add(group);
                return(true);
            }
            catch (Exception ex)
            {
                return(false);
            }
        }
Ejemplo n.º 16
0
        public ActionResult Create(string courseCode)
        {
            GroupCreateModel  gcm = new GroupCreateModel();
            CourseGetResponse cgr = _courseCom.GetCourse(courseCode);

            if (cgr != null)
            {
                gcm.GroupTypeCode = cgr.GroupType;
                if (cgr.GroupSize.HasValue)
                {
                    gcm.MaxNumberOfUsers = cgr.GroupSize;
                }
            }
            gcm.timeZones  = TimeZoneInfo.GetSystemTimeZones().Select(x => x.DisplayName).ToList();
            gcm.CourseCode = courseCode;
            return(View(gcm));
        }
Ejemplo n.º 17
0
        public ActionResult Create()
        {
            var groupList = new[] { new GroupModel {
                                        Name = "(none)"
                                    } }
            .Union(genericJsonPagedQuery.Execute <Group>(null, null, null)
                   .Select(g => new GroupModel {
                Id = g.Id.ToString(), Name = g.Name
            }));

            var model = new GroupCreateModel
            {
                GroupList = groupList
            };

            return(View(model));
        }
Ejemplo n.º 18
0
        public async Task <IHttpActionResult> Create(GroupCreateModel createModel)
        {
            if (!_groupService.CanCreate())
            {
                return(StatusCode(HttpStatusCode.Forbidden));
            }

            var currentMemberId = await _memberService.GetCurrentMemberIdAsync();

            var groupId = await _groupMemberService.CreateAsync(createModel, new GroupMemberSubscriptionModel
            {
                IsAdmin  = true,
                MemberId = currentMemberId,
            });

            return(Ok(_groupLinkProvider.GetGroupRoomLink(groupId)));
        }
Ejemplo n.º 19
0
        public async Task <IActionResult> Create()
        {
            var users = await this.userService.GetUsersAsync();

            var model = new GroupCreateModel
            {
                Users = users
                        .Where(x => x.Name != userService.GetCurrUser().Name)
                        .Select(x => new SelectListItem
                {
                    Text  = x.Name,
                    Value = x.Id.ToString()
                })
                        .ToList()
            };

            return(View(model));
        }
Ejemplo n.º 20
0
        public override string Create(GroupCreateModel model)
        {
            var group = AutoMapperExtensions.Map <GroupModel>(model);

            group.GroupTypeId = GroupTypeEnum.Open.ToInt();

            var createdMedias = _mediaHelper.CreateMedia(model).ToList();

            group.ImageId = createdMedias.Any()
                                ? (int?)createdMedias.First()
                                : null;

            var groupId = _groupService.Create(group);

            Add(groupId, model.Creator);

            _groupMediaService.GroupTitleChanged(groupId, group.Title);

            return(_groupLinkProvider.GetGroupLink(groupId));
        }
 public IActionResult Create([FromBody] GroupCreateModel model)
 {
     if (model == null)
     {
         return(BadRequest());
     }
     try
     {
         var group = (LocalGroup)model;
         db.LocalGroup.Add(group);
         db.SaveChanges();
         return(Ok(group));
     }
     catch (Exception)
     {
         return(BadRequest(new
         {
             message = "На сервере произошла ошибка, попробуйте позже"
         }));
     }
 }
Ejemplo n.º 22
0
        public ActionResult Create(GroupCreateModel createModel)
        {
            if (!ModelState.IsValid)
            {
                return(RedirectToCurrentUmbracoPage(Request.QueryString));
            }

            var group = createModel.Map <GroupModel>();

            group.GroupTypeId = GroupTypeEnum.Open.ToInt();
            var createdMedias = _mediaHelper.CreateMedia(createModel).ToList();

            group.ImageId = createdMedias.Any() ? (int?)createdMedias.First() : null;

            Guid groupId = _groupService.Create(group);

            _groupMediaService.GroupTitleChanged(groupId, group.Title);

            _groupMemberService.Add(groupId, createModel.CreatorId);

            return(Redirect(_groupLinkProvider.GetGroupLink(groupId)));
        }
Ejemplo n.º 23
0
        public async Task <Guid> CreateAsync(GroupCreateModel model, GroupMemberSubscriptionModel creator)
        {
            var group = model.Map <GroupModel>();

            group.CreatorId = await _memberService.GetCurrentMemberIdAsync();

            group.GroupTypeId = GroupTypeEnum.Open.ToInt();

            var createdMedias = _mediaHelper.CreateMedia(model, MediaFolderTypeEnum.GroupsContent).ToList();

            group.ImageId = createdMedias.Any()
                ? (int?)createdMedias.First()
                : null;

            var groupId = await _groupService.CreateAsync(group);

            await AddAsync(groupId, creator);

            await _groupMediaService.GroupTitleChangedAsync(groupId, @group.Title);

            return(groupId);
        }
Ejemplo n.º 24
0
        public ActionResult Create(GroupCreateModel model)
        {
            try
            {
                var group = new Group
                {
                    Name        = model.Name,
                    Description = model.Description,
                    ParentId    = model.ParentId == null ? new Identity?() : new Identity(model.ParentId)
                };

                createGroupCommand.Execute(group);

                return(RedirectToAction("Index"));
            }
            catch (Exception e)
            {
                ModelState.AddModelError(Guid.NewGuid().ToString(), e);
            }
            model.GroupList = GetGroupList();
            return(View(model));
        }
Ejemplo n.º 25
0
        public async Task <Guid> CreateGroup(Guid memoryBookUniverseId, string code, string name, string description)
        {
            Contract.RequiresNotNullOrWhitespace(code, nameof(code));
            Contract.RequiresNotNullOrWhitespace(name, nameof(name));

            try
            {
                var allGroups = await this.groupQueryManager.GetAllGroups(memoryBookUniverseId).ConfigureAwait(false);

                if (allGroups.Any(x => x.Code.Equals(code, StringComparison.OrdinalIgnoreCase)))
                {
                    throw new InvalidOperationException($"Group already existed for with code {code} for universe {memoryBookUniverseId}");
                }

                GroupCreateModel groupCreateModel = new GroupCreateModel
                {
                    Name        = name,
                    Code        = code,
                    Description = description
                };

                var result = await this.groupCommandManager.CreateGroups(memoryBookUniverseId, groupCreateModel)
                             .ConfigureAwait(false);

                if (!result.Success || !result.Ids.Any())
                {
                    return(Guid.Empty);
                }

                return(result.Ids.First());
            }
            catch (Exception ex)
            {
                this.logger.LogError(ex, $"An exception occurred in {nameof(this.CreateGroup)}");
                return(Guid.Empty);
            }
        }
Ejemplo n.º 26
0
        public async Task <IActionResult> Create(GroupCreateModel group)
        {
            await this.groupService.CreateGroupAsync(group.Name, group.UserIds, group.Amount, group.Description);

            return(RedirectToAction("Index", "Home"));
        }
Ejemplo n.º 27
0
        public async Task FullTest()
        {
            var mediator = ServiceProvider.GetService <IMediator>();

            mediator.Should().NotBeNull();

            var createModel = new GroupCreateModel
            {
                Name        = "Group " + DateTime.Now.Ticks,
                Description = "Created from Unit Test",
                TenantId    = Data.Constants.Tenant.Test
            };

            var createCommand = new EntityCreateCommand <GroupCreateModel, GroupReadModel>(MockPrincipal.Default, createModel);
            var createResult  = await mediator.Send(createCommand).ConfigureAwait(false);

            createResult.Should().NotBeNull();

            var identifierQuery  = new EntityIdentifierQuery <Guid, GroupReadModel>(MockPrincipal.Default, createResult.Id);
            var identifierResult = await mediator.Send(identifierQuery).ConfigureAwait(false);

            identifierResult.Should().NotBeNull();
            identifierResult.Name.Should().Be(createModel.Name);


            var entityQuery = new EntityQuery
            {
                Sort = new[] { new EntitySort {
                                   Name = "Updated", Direction = "Descending"
                               } },
                Filter = new EntityFilter {
                    Name = "Name", Value = "Group", Operator = "StartsWith"
                }
            };
            var listQuery = new EntityPagedQuery <GroupReadModel>(MockPrincipal.Default, entityQuery);

            var listResult = await mediator.Send(listQuery).ConfigureAwait(false);

            listResult.Should().NotBeNull();

            var patchModel = new JsonPatchDocument <Group>();

            patchModel.Operations.Add(new Operation <Group>
            {
                op    = "replace",
                path  = "/Description",
                value = "Patch Update"
            });

            var patchCommand = new EntityPatchCommand <Guid, GroupReadModel>(MockPrincipal.Default, createResult.Id, patchModel);
            var patchResult  = await mediator.Send(patchCommand).ConfigureAwait(false);

            patchResult.Should().NotBeNull();
            patchResult.Description.Should().Be("Patch Update");

            var updateModel = new GroupUpdateModel
            {
                Name        = patchResult.Name,
                Description = "Update Command",
                TenantId    = patchResult.TenantId,
                RowVersion  = patchResult.RowVersion
            };

            var updateCommand = new EntityUpdateCommand <Guid, GroupUpdateModel, GroupReadModel>(MockPrincipal.Default, createResult.Id, updateModel);
            var updateResult  = await mediator.Send(updateCommand).ConfigureAwait(false);

            updateResult.Should().NotBeNull();
            updateResult.Description.Should().Be("Update Command");

            var deleteCommand = new EntityDeleteCommand <Guid, GroupReadModel>(MockPrincipal.Default, createResult.Id);
            var deleteResult  = await mediator.Send(deleteCommand).ConfigureAwait(false);

            deleteResult.Should().NotBeNull();
            deleteResult.Id.Should().Be(createResult.Id);
        }
Ejemplo n.º 28
0
 public async Task <ActionResult <Response> > Create(GroupCreateModel model)
 {
     return(await _GroupService.Create(model, User));
 }
Ejemplo n.º 29
0
        public async Task <IActionResult> CreateGroup([FromBody] GroupCreateModel model)
        {
            var result = await _bizGroup.CreateAsync(model);

            return(ToResponse(result));
        }
Ejemplo n.º 30
0
 public async Task <int> CreateGroup(GroupCreateModel model) =>
 await _mediator.Send(new GroupCreateRequest()
 {
     Model = model
 });