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"));
        }
Beispiel #2
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);
        }