Beispiel #1
0
        public async Task <IActionResult> UpdateUnit(int unitId, int groupId, string name, int unitTypeId, string noteText,
                                                     int currentCapacity, int maxCapacity, int monthlyCosts, int colorId, string street, string streetNumber,
                                                     string city, string zip, string state, IFormFile contractFile)
        {
            var unit = await _unitFacade.GetUnitByIdAsync <UnitDTO>(unitId);

            var contract = GetContract(contractFile, unit);

            unit.UnitTypeId       = unitTypeId;
            unit.UnitGroupId      = groupId;
            unit.CurrentCapacity  = currentCapacity;
            unit.MaxCapacity      = maxCapacity;
            unit.Contract         = contract;
            unit.Contract.Name    = contract.Name;
            unit.Contract.Content = contract.Content;
            unit.MonthlyIncome    = monthlyCosts;

            unit.Specification.Name    = name;
            unit.Specification.ColorId = colorId;
            unit.Specification.Note    = noteText;

            unit.Specification.Address.State  = state;
            unit.Specification.Address.City   = city;
            unit.Specification.Address.Street = street;
            unit.Specification.Address.Number = streetNumber;
            unit.Specification.Address.Zip    = zip;

            await _unitFacade.UpdateUnitAsync(unitId, unit);

            return(RedirectToAction("MyUnits", new { groupId }));
        }
Beispiel #2
0
        public async Task <IActionResult> SaveUnit(int unitId, int groupId, string name, int selectColor, string note,
                                                   int selectUnitType, int currentCapacity, int maxCapacity, string contractLink, string state, string city,
                                                   string street, string number, string zip, IFormFile file)
        {
            UnitDTO unit = await _unitFacade.GetUnitByIdAsync <UnitDTO>(unitId);

            var contract = GetContract(file, unit);

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

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

                unit = new UnitDTO()
                {
                    Specification   = spec,
                    UnitGroupId     = groupId,
                    UnitTypeId      = selectUnitType,
                    CurrentCapacity = currentCapacity,
                    MaxCapacity     = maxCapacity,
                    //ContractLink = contractLink ?? string.Empty,
                    Contract = contract
                };

                await _unitFacade.CreateUnitAsync(unit);
            }
            else
            {
                unit.Specification.Name    = name ?? string.Empty;
                unit.Specification.ColorId = selectColor;
                unit.Specification.Note    = note ?? string.Empty;

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

                unit.UnitTypeId      = selectUnitType;
                unit.UnitGroupId     = groupId;
                unit.CurrentCapacity = currentCapacity;
                unit.MaxCapacity     = maxCapacity;
                //unit.ContractLink = contractLink ?? string.Empty;
                unit.Contract         = contract;
                unit.Contract.Name    = contract.Name;
                unit.Contract.Content = contract.Content;

                await _unitFacade.UpdateUnitAsync(unitId, unit);
            }

            return(RedirectToAction("MyUnits", "Units", new { groupId = groupId, unitId = unitId }));
        }
Beispiel #3
0
        public async Task <int> SaveUnitAsync(int groupId, int unitId, string name, int colorId, string note, int unitTypeId,
                                              int currentCapacity, int maxCapacity, string contractLink, string state, string city, string street, string number, string zip)
        {
            UnitDTO unit = await _unitFacade.GetUnitByIdAsync <UnitDTO>(unitId);

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

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

                var contract = new Contract(); // TODO

                unit = new UnitDTO()
                {
                    Specification   = spec,
                    UnitGroupId     = groupId,
                    UnitTypeId      = unitTypeId,
                    CurrentCapacity = currentCapacity,
                    MaxCapacity     = maxCapacity,
                    //ContractLink = contractLink ?? string.Empty,
                    Contract = contract
                };

                await _unitFacade.CreateUnitAsync(unit);
            }
            else
            {
                unit.Specification.Name    = name ?? string.Empty;
                unit.Specification.ColorId = colorId;
                unit.Specification.Note    = note ?? string.Empty;

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

                unit.UnitTypeId      = unitTypeId;
                unit.UnitGroupId     = groupId;
                unit.CurrentCapacity = currentCapacity;
                unit.MaxCapacity     = maxCapacity;
                //unit.ContractLink = contractLink ?? string.Empty;
                unit.Contract = new Contract();

                await _unitFacade.UpdateUnitAsync(unitId, unit);
            }

            return(unit.Id);
        }