コード例 #1
0
 public ActionResult Edit([Bind(Include = "Id,Name,Description,GroupType")] DtoGroup group)
 {
     if (ModelState.IsValid)
     {
         GroupService.Update(group);
         return(RedirectToAction("Index"));
     }
     return(View(group));
 }
コード例 #2
0
        public GroupKey GetGroupKeyFromGroupDTO(DtoGroup dtoGroup)
        {
            var groupKey = new GroupKey()
            {
                Name        = dtoGroup.Name,
                PhoneNumber = dtoGroup.AdminPhoneNumber,
            };

            return(groupKey);
        }
コード例 #3
0
        public DtoGroup GetGroupDtoFromGroup(Group group)
        {
            var dtoGroup = new DtoGroup()
            {
                Name             = group.Name,
                AdminPhoneNumber = group.AdminPhoneNumber
            };

            return(dtoGroup);
        }
コード例 #4
0
        public void ChangeGroupName(DtoGroup dtoGroup, string newName)
        {
            var groupKey = _groupMapping.GetGroupKeyFromGroupDTO(dtoGroup);
            var newKey   = new GroupKey(groupKey.PhoneNumber, newName);
            var exists   = _groupsRepository.UpdateGroupKey(groupKey, newKey);

            if (exists == null)
            {
                throw new Exception("Group doesn't exist!");
            }
        }
コード例 #5
0
        public void Update(DtoGroup Group, List <Position> Positions = null)
        {
            Group oldGroup = GetGroup(CtxDB, OrganizationId, Group.Id);

            oldGroup.Name             = Group.Name;
            oldGroup.Description      = Group.Description;
            oldGroup.LastModifiedDate = DateTime.UtcNow;

            CtxDB.Entry(oldGroup).State = EntityState.Modified;
            CtxDB.SaveChanges();
        }
コード例 #6
0
        public void Insert(DtoGroup Group)
        {
            Group newGroup = new Group
            {
                Name           = Group.Name,
                Description    = Group.Description,
                OrganizationId = OrganizationId,
                CreatedDate    = DateTime.UtcNow
            };

            CtxDB.Groups.Add(newGroup);
            CtxDB.SaveChanges();
        }
コード例 #7
0
        // GET: Groups/Edit/5
        public ActionResult Edit(Guid?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            DtoGroup group = GroupService.Get(id.Value);

            if (group == null)
            {
                return(HttpNotFound());
            }
            return(View(group));
        }
コード例 #8
0
        /// <summary>
        /// Create group.
        /// </summary>
        /// <param name="dto"> Object to be created. </param>
        /// <param name="userId"> Id of the user creating group. </param>
        /// <returns> Response containing created object. </returns>
        public async Task <DtoResponseResult <DtoGroup> > CreateAsync(DtoGroup dto, int userId)
        {
            var entity = _mapper.Map <Group>(dto);

            entity.CreatedById = userId;
            entity.CreatedDate = DateTime.UtcNow;


            var newEntity = _unitOfWork.GroupRepository.Create(entity);


            await _unitOfWork.SaveChangesAsync();

            return(DtoResponseResult <DtoGroup> .CreateResponse(_mapper.Map <DtoGroup>(newEntity)));
        }
コード例 #9
0
 public IActionResult ChangeGroupName([FromBody] DtoGroup dtoGroup, string newName)
 {
     if (!ModelState.IsValid)
     {
         return(BadRequest(ModelState));
     }
     try
     {
         _groupsService.ChangeGroupName(dtoGroup, newName);
         return(Ok());
     }
     catch (Exception)
     {
         return(BadRequest("You are not the admin of this group!"));
     }
 }
コード例 #10
0
        public ActionResult InserOrUpdate([Bind(Include = "Id,Name,Description,GroupType")] DtoGroup group)
        {
            if (ModelState.IsValid)
            {
                if (group.Id != Guid.Empty)
                {
                    GroupService.Update(group);
                }
                else
                {
                    GroupService.Insert(group);
                }
            }

            return(RedirectToAction("Index"));
        }
コード例 #11
0
        public Group GetGroupFromGroupDTO(DtoGroup dtoGroup)
        {
            var sql = "Select U.PhoneNumber FROM dbo.GroupLinks GL " +
                      "Inner Join Users U On U.PhoneNumber = GL.PhoneNumber " +
                      "WHERE GL.AdminPhoneNumber = @AdminPhoneNumber AND " +
                      "GL.GroupName = @Name";
            var users = _dbConnection.Query <string>(sql, dtoGroup).ToList();

            var group = new Group()
            {
                Name             = dtoGroup.Name,
                AdminPhoneNumber = dtoGroup.AdminPhoneNumber,
                Users            = users
            };

            return(group);
        }
コード例 #12
0
        /// <summary>
        /// Update particular group.
        /// </summary>
        /// <param name="dto"> Updated version of an object. </param>
        /// <param name="userId"> Id of the user updating group. </param>
        /// <returns> Response containing created group (dto). </returns>
        public async Task <DtoResponseResult <DtoGroup> > UpdateAsync(DtoGroup dto, int userId)
        {
            var entity = await _unitOfWork.GroupRepository.FindAsync(g => g.Id == dto.Id);

            if (entity == null)
            {
                return(DtoResponseResult <DtoGroup> .FailedResponse("Group not found"));
            }

            _mapper.Map(dto, entity);
            entity.UpdatedById = userId;
            entity.UpdatedDate = DateTime.UtcNow;

            var newEntity = _unitOfWork.GroupRepository.Update(entity, dto.Id);
            await _unitOfWork.SaveChangesAsync();

            return(DtoResponseResult <DtoGroup> .CreateResponse(_mapper.Map <DtoGroup>(newEntity)));
        }
コード例 #13
0
        public Group GetGroup(string name, string adminPhoneNumber)
        {
            var groupDto = new DtoGroup(name, adminPhoneNumber);

            return(_groupMapping.GetGroupFromGroupDTO(groupDto));
        }