public async Task <IActionResult> CreateGroup(string name, int colorId, string street, string streetNumber,
                                                      string city, string zip, string state, string noteText)
        {
            var address = new Address
            {
                State  = state ?? string.Empty,
                City   = city ?? string.Empty,
                Street = street ?? string.Empty,
                Number = streetNumber ?? string.Empty,
                Zip    = zip ?? string.Empty
            };

            var spec = new Specification
            {
                Name    = name ?? string.Empty,
                Note    = noteText ?? string.Empty,
                ColorId = colorId,
                Address = address
            };

            var unitGroup = new UnitGroupDTO
            {
                OwnerId       = UserInfoManager.UserId,
                UserId        = UserInfoManager.UserId,
                Specification = spec
            };

            await _unitGroupFacade.CreateUnitGroupAsync(unitGroup);

            return(RedirectToAction("MyGroups"));
        }
        public async Task UpdateUnitGroupAsync(int id, UnitGroupDTO unitGroupDTO)
        {
            var unitGroup = await _unitOfWork.UnitGroupRepository.GetByIdAsync(id);

            unitGroup.Specification = unitGroupDTO.Specification;

            _unitOfWork.UnitGroupRepository.Update(unitGroup);
        }
Beispiel #3
0
        public async Task <ActionResult <UnitGroupWithSpecificationModel> > GetUnitGroupByIdAsync(int groupId)
        {
            UnitGroupDTO group = await _unitGroupFacade.GetUnitGroupByIdAsync <UnitGroupDTO>(groupId);

            if (group == null)
            {
                return(BadRequest());
            }

            return(Utils.Convert(group));
        }
Beispiel #4
0
        public async Task <int> SaveUnitGroupAsync(int userId, int groupId, string name, int colorId, string note, string state,
                                                   string city, string street, string number, string zip)
        {
            UnitGroupDTO group = await _unitGroupFacade.GetUnitGroupByIdAsync <UnitGroupDTO>(groupId);

            if (group == null)
            {
                Address address = new Address()
                {
                    State  = state ?? string.Empty,
                    City   = city ?? string.Empty,
                    Street = street ?? string.Empty,
                    Number = number ?? string.Empty,
                    Zip    = zip ?? string.Empty,
                };

                Specification spec = new Specification()
                {
                    Name    = name ?? string.Empty,
                    ColorId = colorId,
                    Note    = note ?? string.Empty,
                    Address = address,
                };

                group = new UnitGroupDTO()
                {
                    UserId        = userId,
                    Specification = spec,
                };

                await _unitGroupFacade.CreateUnitGroupAsync(group);
            }
            else
            {
                group.Specification.Name    = name ?? string.Empty;
                group.Specification.ColorId = colorId;
                group.Specification.Note    = note ?? string.Empty;

                group.Specification.Address.State  = state ?? string.Empty;
                group.Specification.Address.City   = city ?? string.Empty;
                group.Specification.Address.Street = street ?? string.Empty;
                group.Specification.Address.Number = number ?? string.Empty;
                group.Specification.Address.Zip    = zip ?? string.Empty;

                await _unitGroupFacade.UpdateUnitGroupAsync(groupId, group);
            }

            return(group.Id);
        }
Beispiel #5
0
 public static UnitGroupWithSpecificationModel Convert(UnitGroupDTO group)
 {
     return(new UnitGroupWithSpecificationModel()
     {
         Id = group.Id,
         UserId = group.UserId,
         Name = group.Specification.Name,
         ColorId = group.Specification.ColorId,
         Color = group.Specification.Color.Name,
         AddressId = group.Specification.AddressId,
         Note = group.Specification.Note,
         State = group.Specification.Address.State,
         City = group.Specification.Address.City,
         Street = group.Specification.Address.Street,
         Number = group.Specification.Address.Number,
         Zip = group.Specification.Address.Zip,
     });
 }
 public void CreateUnitGroup(UnitGroupDTO unitGroupDTO)
 {
     _unitOfWork.UnitGroupRepository.Add(_mapper.Map <UnitGroup>(unitGroupDTO));
 }
        public async Task UpdateUnitGroupAsync(int id, UnitGroupDTO unitGroupDTO)
        {
            await _unitGroupService.UpdateUnitGroupAsync(id, unitGroupDTO);

            await _unitOfWork.CommitAsync();
        }
        public async Task CreateUnitGroupAsync(UnitGroupDTO unitGroupDTO)
        {
            _unitGroupService.CreateUnitGroup(unitGroupDTO);

            await _unitOfWork.CommitAsync();
        }