public async Task <IResponseDTO> CreatePackageType(CreateUpdatePackageTypeDto options, int userId)
        {
            try
            {
                var packageType = new Data.DbModels.LookupSchema.PackageType
                {
                    Name        = options.Name,
                    Description = options.Description
                };

                await _appDbContext.PackageTypes.AddAsync(packageType);

                // save to the database
                var save = await _appDbContext.SaveChangesAsync();

                if (save == 0)
                {
                    _response.IsPassed = false;
                    _response.Message  = "Database did not save the object";
                    return(_response);
                }

                _response.IsPassed = true;
                _response.Message  = "Package type is created successfully";
            }
            catch (Exception ex)
            {
                _response.Data     = null;
                _response.IsPassed = false;
                _response.Message  = "Error " + ex.Message;
            }

            return(_response);
        }
        public async Task <IResponseDTO> UpdatePackageType(int id, CreateUpdatePackageTypeDto options, int userId)
        {
            try
            {
                var packageType = _appDbContext.PackageTypes.FirstOrDefault(x => x.Id == id);
                if (packageType == null)
                {
                    _response.IsPassed = false;
                    _response.Message  = "Invalid id";
                    return(_response);
                }

                packageType.Name        = options.Name;
                packageType.Description = options.Description;

                _appDbContext.PackageTypes.Update(packageType);

                // save to the database
                var save = await _appDbContext.SaveChangesAsync();

                if (save == 0)
                {
                    _response.IsPassed = false;
                    _response.Message  = "Database did not save the object";
                    return(_response);
                }

                _response.IsPassed = true;
                _response.Message  = "Package type is updated successfully";
            }
            catch (Exception ex)
            {
                _response.Data     = null;
                _response.IsPassed = false;
                _response.Message  = "Error " + ex.Message;
            }

            return(_response);
        }
예제 #3
0
        public async Task <IResponseDTO> UpdatePackageType([FromRoute] int id, [FromBody] CreateUpdatePackageTypeDto options)
        {
            _response = await _packageTypeService.UpdatePackageType(id, options, LoggedInUserId);

            return(_response);
        }